mea*_*our 2 python math floating-point python-3.x
我编写了以下代码:
x = 0.01
print(format(x, '0.27f'))
print(format(x, '1.27f'))
print(format(x, '2.27f'))
Run Code Online (Sandbox Code Playgroud)
上述所有打印语句均给出以下输出:
0.010000000000000000208166817
Run Code Online (Sandbox Code Playgroud)
'0.27f'请帮助我理解和'1.27f'之间的区别'2.27f'
格式字符串中的第一个数字是总宽度,而不是小数点左侧的宽度。如果有其他因素迫使表示更长,例如您在所有 3 个示例中请求的小数点右侧的 27 位,则它会被忽略。
通过使总宽度足够大,您可以开始看到差异,例如
print(format(x, '30.27f'))
0.010000000000000000208166817
print(format(x, '31.27f'))
0.010000000000000000208166817
print(format(x, '32.27f'))
0.010000000000000000208166817
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
112 次 |
| 最近记录: |