【发布时间】:2016-10-04 14:43:43
【问题描述】:
看起来 4.5 和 5.5 在 Python 3.5 中都有精确的浮点表示:
>>> from decimal import Decimal
>>> Decimal(4.5)
Decimal('4.5')
>>> Decimal(5.5)
Decimal('5.5')
如果是这样,那为什么
>>> round(4.5)
4
>>> round(5.5)
6
?
【问题讨论】:
-
银行家的四舍五入。你四舍五入到最接近的偶数
标签: python floating-point floating-accuracy