Jump to content

Recommended Posts

Posted

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?

 

 

 

Thanks!

Posted
Thanks! Unfortunately this doesn't work. Just as with my version, it's returning the percentage sign in front of the number. It need the symbol after the number.
Posted

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;

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.

Guest
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...