【发布时间】:2015-08-08 05:03:10
【问题描述】:
最近,我在 Python 2.7 中学习了字符串格式化的艺术。
我决定玩浮点数。
遇到了一个看起来很尴尬的解决方案,如下所示。
print "%.0f"%45.5000000 #46
print "%.0f"%0.5000000 #0
#Why??
但是
print int(round(45.5000000)) #46
print int(round(0.5000000)) #1
请帮助我理解,为什么%f会显示这种行为。
【问题讨论】:
标签: python python-3.x python-2.7 string-formatting python-internals