15 lines
441 B
Python
15 lines
441 B
Python
|
||
|
||
if __name__ == '__main__':
|
||
x = 1234.56789
|
||
# 对数值格式化输出,我们使用经典format函数
|
||
print(format(x, '.2f'))
|
||
print(format(x, '+<10.2f'))
|
||
print(format(x, '=>10.2f'))
|
||
print(format(x, '-^10.2f'))
|
||
# 有一些特殊的,比如数值特有的千位逗号1,000
|
||
print(format(x, ',.2f'))
|
||
# 如果想用科学计数法,把f改成e就行
|
||
print(format(x, '.2e'))
|
||
print(format(x, 'e'))
|