round Python · 内置函数
就近舍入;遇到正好一半时取最近的偶数(银行家舍入),不是普通四舍五入。
怎么用
round(数字, 保留小数位数)
小例子
print(round(3.6)) print(round(3.14159, 2)) print(round(2.5)) print(round(3.5))
运行结果
4 3.14 2 4
提醒:round(2.5) 是 2,round(3.5) 才是 4。
官方文档:https://docs.python.org/zh-cn/3/library/functions.html#round
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条