According to the MSDN article found at http://msdn.microsoft.com/en-us/library/wyk4d9cy.aspx the floating-point value .1 has no finite binary representation, the first call to the Round(Double) method with a value of 11.5 returns 11 instead of 12.
I can’t clearly understand, why does it happen?
According to the MSDN article found at http://msdn.microsoft.com/en-us/library/wyk4d9cy.aspx the floating-point value .1 has no
Share
The first call isn’t really using 11.5. It’s using a value slightly less than 11.5 due to an accumulation of errors from adding 0.1 repeatedly. Here’s the output if you use my
DoubleConverter.ToExactStringto show the exact values being passed in:At that point, all the results make sense.