python中的四舍五入函数

时间:2019-03-09 05:52:03

标签: python-3.x

round函数在python中似乎很棘手。 对于回合(51.665,2),它显示 51.66 回合(51.765,2)显示 51.77 。 为什么会这样?enter image description here

1 个答案:

答案 0 :(得分:0)

这与浮点数的二进制表示形式有关(以10为底的数字有时不精确地以2为底)。理由在this answerthis one中有更详尽的描述。从理论上讲:What causes floating point rounding errors?

要注意的是Python interpreter displays rounded floating point numbers

相关问题