Python math.ceil()
math.ceil(x) function returns the smallest integer greater than or equal to x.
Syntax
The syntax to call ceil() function is
math.ceil(x)
where
Parameter | Required | Description |
---|---|---|
x | Yes | A numeric value. |
If x is infinity, then ceil(x) raises OverflowError.
If x is nan, then ceil(x) raises ValueError.
Examples
Ceiling of floating point number.
Output
ceil(x) : 6
Ceiling value of negative floating point number
Output
ceil(x) : -5
Ceiling value of infinity.
Output
OverflowError: cannot convert float infinity to integer
Ceiling value of an integer.
Output
ceil(x) : 5
Ceiling value of nan.
Output
ValueError: cannot convert float NaN to integer
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.ceil() function.
Next Topic ⫸
Python Math comb()
⫷ Previous Topic
Python Math all tutorials