Python/ref math ceil
来自菜鸟教程
<languages />
Python math.ceil()方法
例
将数字向上舍入到最接近的整数:
# Import math library
import math
# Round a number upward to its
nearest integer
print(math.ceil(1.4))
print(math.ceil(5.3))
print(math.ceil(-5.3))
print(math.ceil(22.6))
print(math.ceil(10.0))
定义和用法
The
math.ceil()
方法根据需要将数字UP舍入到最接近的整数,然后返回结果。
Tip:
要将数字DOWN舍入到最接近的整数,请查看
math.floor()
方法。
句法
math.ceil(x)
参数值
| 参数 | 描述 |
|---|---|
| x | 需要。指定要舍入的数字 |
技术细节
| 返回值: | An
|
| 变更记录: | Python 3+:返回一个
|