Python浮动部门不完全 [英] Python Float Division Not Exact
本文介绍了Python浮动部门不完全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Python float division似乎没有准确的结果。有人可以解释为什么?
>>> 3.0 / 5
0.59999999999999998
解决方案简单的答案:浮动使用有限精度的二进制编码来表示数字,所以各种操作都会丢失一些精度。
维基百科页面有很多信息(可能太多)。
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
解决方案 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?
这篇关于Python浮动部门不完全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文