Rounding bug mimics ‘banker’ rounding

Monday 19 October 2009 @ 10:32 am

There are two types of rounding in Crystal Reports.  I call them ‘real’ rounding and ‘fake’ rounding. Fake rounding is what you do when you use the toolbar button or Format>Field to reduce the number of decimals.  Real rounding is when you write a formula field using the Round() function.  I usually avoid fake rounding because it doesn’t change the underlying values.  So if you total a column that uses fake rounding your total won’t match the visible values in the column.

Last week a user wrote that fake rounding was using ‘Banker’ rounding which rounds 5 to the nearest even number rather than always rounding up. He asked how to turn off the banker rounding.  I had never heard of Crystal using banker rounding so I did some tests and found that in versions 9 – 11 of Crystal, you do get some odd rounding that might fool you into thinking that CR is doing banker rounding.  But after a bit more testing I realized that what looks like banker rounding is really just a bug in the program.

The first clue that it was a bug was that it only affects numbers that have four or more decimals. Rounding two or three  decimal numbers with fake rounding  will always round a 5 up in the traditional way.  Then, even on these four or five decimal numbers, it will round a 5 to both odd and even numbers.  Banker rounding should consistently round to the nearest even number.   To see this visually you can see my test report (pdf) that shows the dispersion of the rounding error in 600 consecutive values ending in 5.   Note the inconsistent pattern in the values that are rounded down.

This bug does not affect version 8.5 or version 12 (CR 2008).

Leave a Reply

Recrystallize Pro

Crystal Reports Server