Python math.ceil() Method
Python math.ceil(x)The method rounds x up to the nearest integer.
math.floor()The method rounds a number down to the nearest integer.
Syntax
The syntax of the math.ceil() method is as follows:
math.ceil(x)
Parameter Description:
- x-- Required, a number. If x is not a number, returns TypeError.
Return Value
Returns an integer representing the rounded number.
Example
The following example returns the number rounded up to the nearest integer:
Example
# Import the math package
import math
# Output the number rounded up to the 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))
import math
# Output the number rounded up to the 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))
Output result:
2 6 -5 23 10Other Extensions
Python math Module