python中用round函数保留两位小数
发布时间:2025-11-27 20:53:45

本教程的操作环境:windows7系统,Python 3.9.1,DELL G3电脑。
1、round函数
python的内置函数,四舍五入用于数字。
2、round 负数四舍五入是围绕0计算的示例round(0.5)#1.0 round(-0.5)#-1.03、示例:保留两个小数码代码
s=1.23567 result=round(s,2) print(result) 1.24
以上是使用round函数保留两位小数的方法。如果需要保留其他位数的小数,可以更改保留位数。
