Rounding in the Rating
Hi Guys
Is it possible to round values to a set decimal or even integer (i.e. nearest £100) in the rate set? I know that some functions work such as Max & Floor? How about ROUND or ROUNDUP?
What would the syntax be?
Many thanks
John

Hi John,
You may be able to use Math.Round(number) for this though there are some caveats, since Math.Round(1.5) and Math.Round(2.5) both round to 2 (3.5 would round up to 4 and that 4.5 would round down to 4). This is because the default behaviour in .admScript is for this to use MidpointRounding.ToEven.
Most people are not familiar with "rounding to even" as the alternative, "rounding away from zero" is more commonly taught in school. .admScript defaults to "Rounding to even" as it is statistically superior because it doesn't share the tendency of "rounding away from zero" to round up slightly more often than it rounds down (assuming the numbers being rounded tend to be positive.)
You can improve it by doing Math.Round(number, MidpoindRounding.AwayFromZero) though whether this will work in the rating file I'm not sure, you're breaking new ground here a bit :)
The only way to really get the value to round properly (financially) is multiply, truncate and then divide (i.e. for 2 decimal places n = int(v * 100 +.5) / 100).
Best wishes,
Adam

Hi,
Just thought I'd add that you can use CEILING() to always round up, you just need to get the decimal point in the right place:
101 round up to 200 = CEILING(101/100.0) * 100 = CEILING(1.01) * 100
You can obviously also use it for rounding up thousands etc.
FLOOR() works in the same way for always rounding down.
Thanks,
Rob.
Please sign in to leave a comment.
Comments
3 comments