Why does 99.99 / 100 = 0.9998999999999999 [duplicate]

房东的猫 提交于 2019-11-28 12:45:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!