Python四舍五入问题 [英] Python rounding problem
本文介绍了Python四舍五入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
>>> num = 4.123456
>>> round(num, 3) # expecting 4.123
4.1230000000000002
我期待4.123结果,我错了吗?
I'm expecting 4.123 as a result, Am I wrong?
推荐答案
如果你想有一个精确的表示你的浮点数号码,你必须使用 decimal
。
If you want to have an exact representation of your floating point number, you have to use decimal
.
这篇关于Python四舍五入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文