Jump to content

Replace Symbol


Recommended Posts

Hello all,



Trying to come up with a way to remove a percentage symbol if it already exists in the data but return the symbol if it does not exist.



I already successfully created a replace rule for the presence of a dollar sign:


return Field("Price").replace('$', "");



If I simply replace the dollar symbol with a percentage symbol, I'm not getting the same result:

return Field("Percent").replace("", '%');



Any ideas on what I'm obviously doing wrong?





Link to comment
Share on other sites

I believe you have the order of your parameters switched on your percentage example.


With replace the first parameter is what you are searching for, and the second is what to replace it with.


Here's a bit of code that covers both $ and %:


var fieldName = Field("field");

var field = fieldName.replace(/\$/g,'').replace(/\%/g,'');

if(fieldName.indexOf('$') > -1){return '$' + field;}
if(fieldName.indexOf('%') > -1){return field + '%';}

return field;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...