Python整数格式 [英] Python integer formatting
本文介绍了Python整数格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道在格式化整数时是否可以同时使用两种格式选项.
I was wondering if it's possible to use two format options together when formatting integers.
我知道我可以使用波纹管来包含零个位置
I know I can use the bellow to include zero places
varInt = 12
print(
"Integer : " +
"{:03d}".format(varInt)
)
获取输出整数:012"
To get the output "Integer : 012"
我可以使用以下内容来包含小数位
I can use the following to include decimal places
varInt = 12
print(
"Integer : " +
"{:.3f}".format(varInt)
)
获取输出整数:12.000"
To get the output "Integer : 12.000"
但是是否可以将它们一起使用以获得输出整数:012.000"
But is it possible to use them both together to get the output "Integer : 012.000"
推荐答案
varInt = 12
print(
"Integer : " +
"{:07.3f}".format(varInt)
)
输出:
Integer : 012.000
<小时>
7 是总字段宽度,包括小数点.
The 7 is total field width and includes the decimal point.
这篇关于Python整数格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文