【七种常见的字符串格式化方法】
参考链接: 七种常见的字符串格式化方法
1、保留小数点后两位
>>>print("{:.2f}".format(3.1415))
3.14
2、带符号保留小数点后两位
>>>print("{:+.2f}".format(-3.1415))
-3.14
3、不带小数点
>>>print("{:.0f}".format(2.7))
3
4、整数补零,填充左边, 宽度为3
>>>print("{:0>3d}".format(6))
006
5、以逗号分隔的数字格式
>>>print("{:,}".format(123456789))
123,456,789
6、百分比格式
>>>print("{:.2%}".format(0.94545)) # 百分比小数点后两位
94.55%
7、指数记法
>>>print("{:.2e}".format(123456789)) #科学计数法,小数点后两位
1.23e+08