Floating point error in representation?

蹲街弑〆低调 提交于 2019-11-26 06:49:36

问题


when i make this multiplication

0.94 * 8700

the output is

8177.999999999999

but it should have been

8178

i\'m using java , but i don\'t think this error is related to a particular Programming language now my question is ... why this happened ??
and what other numbers (just as an example) cause the same error?


回答1:


The specific reason in your case is that the real number 0.94 cannot be represented exactly in a double precision floating point. When you type 0.94, the actual number stored is 0.939999999999999946709294817992486059665679931640625.




回答2:


It isn't an error. IEEE floats can't represent decimal numbers exactly.



来源:https://stackoverflow.com/questions/7581741/floating-point-error-in-representation

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