-Lisa- Posted May 16, 2019 Posted May 16, 2019 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! Quote
Leosmith Posted May 16, 2019 Posted May 16, 2019 return Field("Percent").replace("", ' & # 3 7 ; ');remove the spaces in ascii % check - treat return string as tagged text Quote
-Lisa- Posted May 16, 2019 Author Posted May 16, 2019 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. Quote
ScottHillock Posted May 17, 2019 Posted May 17, 2019 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; Quote
Recommended Posts
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.