Python | 保留指定位数的小数

format函数

print(format(1.23456, '.2f'))
print(format(1.23456, '.3f'))
print(format(1.23456, '.4f'))
1.23
1.235
1.2346

这个方法会进行四舍五入

参考资料:Python保留指定位数的小数_Lavi的专栏-CSDN博客_python 保留几位小数

猜你喜欢

转载自blog.csdn.net/weixin_48419914/article/details/121740353