示例
print('%.2f' % 1.255)
# 1.25
print('{:.2f}'.format(1.2635))
# 1.26
print(format(1.235, '.2f'))
# 1.24
print(round(1.23456, 2))
# 1.23
参考 Python保留小数的方法
Python:浮点数保留小数位数的方法整理
阅读 170
2022-10-05
示例
print('%.2f' % 1.255)
# 1.25
print('{:.2f}'.format(1.2635))
# 1.26
print(format(1.235, '.2f'))
# 1.24
print(round(1.23456, 2))
# 1.23
参考 Python保留小数的方法
相关推荐
精彩评论(0)