0
点赞
收藏
分享

微信扫一扫

Python:浮点数保留小数位数的方法整理

示例

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 条评论