Python3 ceil() Function
Description
The ceil(x) function returns the smallest integer greater than or equal to x.
Syntax
The syntax of the ceil() method is as follows:
import math
math.ceil( x )
**Note:** ceil() cannot be accessed directly; you need to import the math module and call the method through the static object.
Parameters
x -- a numeric expression.
Return Value
The function returns the smallest integer greater than or equal to x.
Example
The following shows examples of using the ceil() method:
#!/usr/bin/python3
import math # 导入 math 模块
print ("math.ceil(-45.17) : ", math.ceil(-45.17))
print ("math.ceil(100.12) : ", math.ceil(100.12))
print ("math.ceil(100.72) : ", math.ceil(100.72))
print ("math.ceil(math.pi) : ", math.ceil(math.pi))
Running the example above produces:
math.ceil(-45.17) : -45
math.ceil(100.12) : 101
math.ceil(100.72) : 101
math.ceil(math.pi) : 4
Python3 Numbers