Saturday, November 12, 2005

.Net Rounding

Trying to round money in C#? Watch out for Decimal.Round and Math.Round. Both rounding functions implement Banker's Rounding aka Rounding by Evens (IEEE Standard 754, section 4.)

What does this mean when you calculate tax? You might owe tax you did not collect.
1.005 rounds to 1.00
1.015 rounds to 1.02

So unless you have a Superman III plan of stealing fractions of pennies, watch your rounding!!

0 Comments:

Post a Comment

<< Home