Python ceil()
function exists in standard math library of Python. By using this function, we can get the ceiling value of any number. Ceiling means to round the number up to the nearest integer.
Example: What is the ceiling of 3.4 in the following:
In the above number line, the ceiling (round up) value of 3.4 is 4.
In Python, we can attain ceiling value of 3.4 by applying math.ceil()
function.
Note: This function cannot be accessed directly. We need to import math library first, then we call this function as a static function of Python math library.
Python ceil()
Function Syntax
The syntax of ceil()
function in Python is:
math.ceil(n)
Python ceil()
Function Parameter
Parameter n is any number.
In this function, the parameter n is required.
In this function, the parameter n is required.
Python ceil()
Function Compatibility
Python 2.x – Yes
Python 3.x – Yes
Python 3.x – Yes
Python ceil()
Function Return Value
The function will return ceiling value (round up to the nearest integer) of numeric expression n. The return value is not less than n, instead, it is equal to or greater than n.
Python ceil()
Function Examples
import math # you have to import math library first print(math.ceil(3.4)) print (math.ceil(0.70)) print (math.ceil(-0.30)) print (math.ceil(1.7)) print (math.ceil(6)) print (math.ceil(-6.1)) print (math.ceil(-6.7))
ceil()
Function Output:
4
1
0
2
6
-6
-6