Python浮动部门不完全 [英] Python Float Division Not Exact

查看:136
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆