数字的格式化操作
2020-05-03 本文已影响0人
飞跑的蛤蟆
In [6]: print('{:.4f}'.format(3.14159265)) # 保留小数点后四位
3.1416
In [7]: print('{:+.4f}'.format(3.14159265)) # 带符号的保留小数点位数
+3.1416
In [8]: print('{:+.4f}'.format(-3.14159265))
-3.1416
In [6]: print('{:.4f}'.format(3.14159265)) # 保留小数点后四位
3.1416
In [7]: print('{:+.4f}'.format(3.14159265)) # 带符号的保留小数点位数
+3.1416
In [8]: print('{:+.4f}'.format(-3.14159265))
-3.1416