Python Float Division Not Exact [duplicate]

耗尽温柔 提交于 2019-12-12 03:06:36

问题


Possible Duplicate:
Python float - str - float weirdness

Python float division does not appear to have accurate results. Can someone explain why?

>>>3.0/5
0.59999999999999998

回答1:


Short answer: Floats use finite-precision binary encoding to represent numbers, so various operations lose some precision.

The Wikipedia page has a lot of information (maybe too much).

See also: How do I use accurate float arithmetic in Python?




回答2:


Floating point arithmetic is not exact; there are rounding errors that are worsened by the fact that computers use binary floating point and not decimal floating point. See Wikipedia.



来源:https://stackoverflow.com/questions/8120914/python-float-division-not-exact

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