每天CookBook之Python-043
- 数字格式化输出
x = 1234.56789
print(format(x, '0.2f'))
print(format(x, '>10.1f'))
print(format(x, '<10.1f'))
print(format(x, '^10.1f'))
print(format(x, ','))
print(format(x, '0,.1f'))
print(format(x, 'e'))
print(format(x, '0.2E'))
print('The Value is {:0,.2f}'.format(x))
print('%0.2f' % x)
print('%10.1f' % x)
print('%-10.1f' % x)
Out:
1234.57
1234.6
1234.6
1234.6
1,234.56789
1,234.6
1.234568e+03
1.23E+03
The Value is 1,234.57
1234.57
1234.6
1234.6
Process finished with exit code 0