首页 › 参考手册 › 内置函数 › round()

Python round() 函数

描述

四舍五入到指定的小数位数。注意 Python 采用"银行家舍入":恰好在中间时舍入到最近的偶数。

语法

round(number[, ndigits])

参数

参数说明
number数字
ndigits保留的小数位数,默认 0

返回值

数字

实例

print(round(3.14159, 2))
print(round(2.5), round(3.5))   # 银行家舍入
print(round(1234.5, -2))
以上实例输出结果为:
3.14
2 4
1200.0