【发布时间】:2021-10-12 22:30:12
【问题描述】:
>>> round((611.05/10.0),2)
61.1
>>> round((611.05/10.0),3)
61.105
我怎样才能获得 61.11?
我尝试了以下但结果相同
>>> ctx = decimal.getcontext()
>>> ctx.rounding = decimal.ROUND_HALF_UP
【问题讨论】:
-
试试
format(611.05 / 10.0, ".40f")- 它是61.10499999999...,略小于你试图四舍五入的一半。 -
你不能得到 61.11,因为 61.1049 不应该四舍五入到 61.11。检查这个stackoverflow.com/questions/588004/…
-
欢迎来到浮点数学世界0.30000000000000004.com
标签: python python-3.x python-2.7