问题
Possible Duplicate:
Dealing with accuracy problems in floating-point numbers
Whereas 99.99 * 0.01 = 0.99
Clearly this is the age old floating point rounding issue, however the rounding error in this case seems quite large to me; what I mean is I might have expected a result of 0.99990000001 or some similar 'close' result.
And for the record I got the same answer in a JavaVM and in a .Net environment.
回答1:
Why 0.9998999999999999 is not close enough for you (and 0.9999000000000001 is good )?
abs(0.9999 - 0.9998999999999999) == abs (0.9999 - 0.9999000000000001)
回答2:
It is a floating point error. For (a lot) more detail see this wikipedia article. Use a decimal
if you need accurate fractional results (see here).
来源:https://stackoverflow.com/questions/2930314/why-does-99-99-100-0-9998999999999999