|
|
1
86
看见 PEP 3101 : 'g' - General format. This prints the number as a fixed-point
number, unless the number is too large, in which case
it switches to 'e' exponent notation.
新样式3.6+:
|
|
|
2
18
实际上,只是
自从
|
|
|
3
9
|
|
|
4
8
|
|
|
5
8
不过,请注意,在我的系统0.100000000000001上,Python将0.1表示为不精确的浮点。 |
|
|
6
8
外面有这么多丑陋的东西
然后你就可以正常打印了。 |
|
|
7
7
|
|
|
8
4
如果只关心精度的小数点后1位(如示例中所示),则可以执行以下操作:
这会将数字转换为小数点后1位的字符串,如果是零,则将其删除:
|
|
|
9
3
|
|
|
10
2
使用Python的 string formatting (使用 str.format() 使用Python 3.0时):
|
|
|
11
2
以下代码将按原样转换变量no的内容,即。
|
|
|
12
1
|
|
|
13
0
|
|
|
14
0
FWIW,带Jinja2,其中var=10.3
|
|
|
15
0
印刷品:
|
|
16
-2
请使用0精度,如果需要,请添加句点。例如“%.0f。”
|