14. Floating Point Arithmetic: Issues and Limitations
It’s easy to forget that the stored value is an approximation to the
original decimal fraction, because of the way that floats are
displayed at the interpreter prompt. Python only prints a decimal
approximation to the true decimal value of the binary approximation
stored by the machine. If Python were to print the true decimal value
of the binary approximation stored for 0.1, it would have to display
Python print命令自动截断数字。上面的评论中有一些解释。如果要打印完整值,请尝试使用
print "%13f" % maximum
显示完整值别担心} 来证明:
max
没有坏,而且maximum
确实持有2.300000000001
。print
但是,在打印时会将其舍入。你可以用^{从the doc:
答:您得到的结果是好的,但
print
会使它更圆。你知道吗您可以使用repr()检查实际值:
相关问题 更多 >
编程相关推荐