Skip to main content
 首页 » 编程设计

Python 舍入问题

2025年05月04日10cloudgamer

>>> num = 4.123456 
>>> round(num, 3) # expecting 4.123 
4.1230000000000002 

我期望结果是 4.123,我错了吗?

请您参考如下方法:

这不是错误。您需要阅读 What Every computer Scientist Should Know About Floating Point Arithmetic:

http://docs.sun.com/source/806-3568/ncg_goldberg.html