Home >>Python math Module >Python math.ceil() Method

Python math.ceil() Method

Python math.ceil() Method

Python math.ceil() Method in python is used to return the smallest integral value which is greater than the number nearest integer and it accepts a number/numeric expression.

Syntax:
math.ceil(x)

Parameter Values

Parameter Description
x It is required you want to round upwards the number. If value is not a number, a TypeError occurs.
Here is an example of Python math.ceil() Method:

import math
print(math.ceil(0.9))
print(math.ceil(2.7))
print(math.ceil(-1.5))
print(math.ceil(13.7))

Output:
1
3
-1
14
Example 2:

import math
p1 = 3.18
p2 = 3.43
p3 = 3
p4 = -3.62
p5 = 0
print("ceil(p1): ", math.ceil(p1))
print("ceil(p2): ", math.ceil(p2))
print("ceil(p3): ", math.ceil(p3))
print("ceil(p4): ", math.ceil(p4))
print("ceil(p5): ", math.ceil(p5))

Output:
ceil(p1): 4
ceil(p2): 4
ceil(p3): 3
ceil(p4): -3
ceil(p5): 0

No Sidebar ads