Python math.floor() 方法
实例
将数字向下舍入取整:
#Import math libraryimport math# Round numbers down to the nearest integerprint(math.floor(0.6))print(math.floor(1.4))print(math.floor(5.3))print(math.floor(-5.3))print(math.floor(22.6))print(math.floor(10.0))
定义与用法
math.floor() 方法将数字向下舍入取最接近的整数(向下取整),并返回结果。
提示:要将数字向上取最接近的整数,请查看 math.ceil() 方法.
语法
math.floor(x)
参数值
| 参数 | 描述 |
|---|---|
| x | 必填。指定要向下舍入的数字 |
技术细节
| 返回值: | 一个 int 值, 取整后的数字 |
|---|---|
| 修改日志: | Python 3+ : 返回一个 int 值Python 2.x : 返回一个 float 值 |