Hello everyone.
I have a rounding issue inside of .Net.
I am rounding a 3 digit number down to two digits and it is causing some problems with one number.
If I try to round 34.425 to two decimal places it should round it to 34.43. I am using the roundawayfromzero option and it has worked for every number in the program except for this one so far.
The code Math.Round(34.425, 2, MidpointRounding.AwayFromZero)
should equal 34.43 however, it equals 34.42.
If I try this with any other number it works fine.
Math.Round(34.435, 2, MidpointRounding.AwayFromZero) = 34.44
Math.Round(34.225, 2, MidpointRounding.AwayFromZero) = 34.23
Math.Round(34.465, 2, MidpointRounding.AwayFromZero) = 34.47
I just wanted to check to see if anyone has run into this problem before?
For right now I have fixed this problem by converting the number to a decimal. I have changed the code to this and it works fine now:
Math.Round(CDec(34.425), 2, MidpointRounding.AwayFromZero) = 34.43
I am just looking for a reason on why my old code did not work.
Thank you!
Updated the code to the correct AwayFromZero