Rounding to 2 decimal places

anandgb

New member
Local time
Yesterday, 23:49
Joined
Dec 27, 2006
Messages
1
I am computing a value based on a %. If I round and the answer is say 100.125 the result is 100.12 instead of 100.13.

If I add 0.005 I will get the correct value for this, but if I get an answer of say 100.3848 and I round it after adding the .005, my answer is wrong.

My problem would be solved if I could test the number of digits after teh decimal place.

using the right(Cinput, 1) function to test the last decimal, it returns either the 2nd, 3rd or 4th digits depending on how many decimal places there are.

Any help would be appreciated
 
rounding is normally done to the neearest even digit, so some round up, and others round down. if you want to do something different, you need to do your own.

how many digits do you need to work to. one trick is to scale up, to get everytihng in whole numbers, then use "int" to get rid of residual decimals, and then divide back by the scale factor.

you need to try a few different things, till you get the result you want.
 
Access/VBA uses "banker's rounding". The other type of rounding taught at school (rounds up from the halfway) is not especially "correct" but in fact arbitrary and not particularly sensible.

Banker's rounding is preferred because it tends to equalise over a large number of roundings.
 

Users who are viewing this thread

Back
Top Bottom