Rounding in the Rating



  • Avatar
    John Levett

    Hi, I had a thought about this and we could probably do a work around using a table but this would be pretty bulky and unelegant.

    Comment actions Permalink
  • Avatar
    Adam Bishop

    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,



    Comment actions Permalink
  • 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.



    Comment actions Permalink

Please sign in to leave a comment.