2025-09-10:仓库迁移
This commit is contained in:
14
3.数字日期和时间/3.对数值做格式化输出.py
Normal file
14
3.数字日期和时间/3.对数值做格式化输出.py
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
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'))
|
Reference in New Issue
Block a user