Keep two decimal places after the decimal point
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Which function is to keep two decimal places after the decimal point?
I try round and SmartRound, It doesn't seem to be working.
- Labels:
- Common Use Cases
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @phoebe_90
Sounds like round should be the right function. Make sure you're using 0.1 as the parameter to round to the nearest hundredth.
You should also be able to use the fixed decimal data type as an alternative if you desire.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello @phoebe_90
The approach @JamesCharnley mentioned will work in most cases, however depending on the number of decimal places, there are edge cases where a simple round() function will not work. This is because the round() function looks 1 decimal place to the right of the number of decimal places you specify in the function. For example:
12.1256 rounded to 2 decimal places would give you 12.13 because the value of the 3rd decimal is >=5
12.1246 rounded to 2 decimal places would give you 12.12 because the value of the 3rd decimal is <=5, even though the last decimal is a 6
Attached is a way around this.
