python 3 四舍五入round 会倾向于偶数(四舍五入)

https://blog.csdn.net/u013249853/article/details/105282846

print(round(2.5)) # 输出 2
print(round(1.5)) # 输出 2
# 四舍五入的方法细节:

print("%.3f" % 0.3345)

print(f'{0.3345:0.3f}')

from decimal import Decimal
print(Decimal(3.3333336).quantize((Decimal("0.00"))))

猜你喜欢

转载自blog.csdn.net/weixin_54217632/article/details/120044114