Full Version: Double Number Rounding Not Consistent
marcnz
Hi,
He have to calculate values at 3 decimal places in a control set Fixed 3 decimal. But we type in sometimes number with 4 decimals and we expect Access to round it accurately. any trailing 5 and more should round up.
I have set a message box to see exactly what happens for some numbers input and I have attached the screenshot.
HAs you can see:
0.0205 rounds to 0.021 which is expected
6.5915 rounds to 6.591 which is not expected.
Interestingly, the value of 6.5915 is actually considered as 6.4614998......! thus, considering it lower than 6.5915 as typed in!
Anybody has a fix for this?
Thanks.
Jeff B.
Search on-line for "Banker's Rounding". MS Access and MS Excel do NOT use the same rounding rule.
The "problem" with always rounding up on "5" or more is that 1,2,3,4 rounds down, and 5,6,7,8,9 round up. Notice that there's one more digit in the "up" rounding?!?
Osuspect what you're seeing is a variation on the "5-up" rule that says that even-number digits preceeding the "5" cause the round to go up, while odd-number digits preceeding the "5" cause a 'round-down'. That should, theoretically, end up with a more even distribution of rounding.
Just try explaining that to everyone in the world, who learned the "5-up" rounding rule in school!
MikeLyons
Computers just don't do fractions that well... there is always going to be some amount of rounding error if you do deep enough into decimal places.
ome people like to use the Currency data type as it is really not a floating point type at all but rather a "scaled integer" type and supports up to four "decimal places" through division by factors of ten.
Mike
pere_de_chipstick
Hi marcnz
Back Leach suggested:
FormatNumber(Number, NumDigitsAfterDecimal)
in this post, he added a caveat later in the thread, but might be worth looking at.
hth
rbianco