Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> a = decimal.Decimal("0.5")
>>> decimal.getcontext().rounding = decimal.ROUND_UP
>>> print round(a)
1.0
感觉 @
riaqn 是正解,是Python 3的round函数对策略做了调整
这个取整是“四舍六入五留双”
http://zh.wikipedia.org/zh-cn/%E6%95%B0%E5%80%BC%E4%BF%AE%E7%BA%A6我记得第一次见到这种取整规则是在大物实验上= =