Zoho Deluge: Regex Rounding and/or Removing Trailing Zeros
- Joel Lipman
- Zoho
- Hits: 5237
A very quick article on a cool snippet of code, another regular expression, I've been trying out to round up a number or at least to remove the trailing zeros. I could have added this to my Zoho Deluge - Some Useful Regular Expressions list but I felt this deserved its own article.
Why?
A client wanted the discount displayed on a template and if they gave 10% discount, it would display as 10.00%. And they need the decimal because sometimes they might offer 12.5%. But when it displays in a template, it isn't that pretty to look at: Instead, could they have 10% to display instead of 10.00%, and display 12.5% instead of 12.50%.
Well there might be a longer solution without using a regular expression (regex), as in check for the decimal point, check each digit thereafter to see if there are zeros... But I'm keen on avoiding using loops where possible so we don't breach a statement execution limit in the Zoho app function.
How?
If we're not going to use loops, then the next best thing I'm aware of is a regular expression.