>Thongchai,
>
>The sum of rounded set of numbers is not the same as the rounded sum of a set of numbers. For example;
>
>
> Rounded
> 12.156 12.16
> 10.506 10.51
> 11.906 11.91
> 10.016 10.02
>SUM
> 44.584
>Rounded
> 44.58 44.60
>
>
>This is a fact of mathematics adn is called a rounding error. The only way to eliminate it form your calculations is to NEVER round any number until the entire calculation is completed. Don't round the numbers as you go along, round the sum.
[To Thongchai]
It is, if you want to take care of overal precision and calculate as good as you can. OTOH, if you do have to do some rounding along the way, because the intermitent results will be rounded when printed and seen as such by some people who don't know theory, then store the rounded numbers into your tables, and never re-round them again - use them as they are. You'll be way off in your calculations (as Jim's example clearly shows), but you' won't get into a situation that some clerk takes a hand calculator and sums the printed numbers (like in the right column here) and gets 44.60, and your routine calculates 44.58. You won't be able to explain that 44.58 is more accurate.
Another bad thing to do is have the numbers grouped, summed by group, and then the group sums rounded, and then totalled in two different ways of grouping. Like, summing price*qty by items, rounding, summing item totals, and OTOH summing the same per invoice and then totalling the invoices. There's a very low probability that the grand totals will be the same. I remember having sat with a customer for six hours over $2 worth of roundup error (on a total of $10000)... and they didn't let me pay it and go home.