Python math.ceil() Method
Example
Round a number upward to its nearest integer:
# Import math library
import math
# Round a number upward to its
nearest integer
print(math.ceil(1.4))
print(math.ceil(5.3))
print(math.ceil(-5.3))
print(math.ceil(22.6))
Try it Yourself »
Definition and Usage
The math.ceil()
method rounds a number upwards to the nearest integer, and returns the result.
Syntax
math.ceil(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. The number you want to round upwards. If x is not a number, a TypeError occurs. |
Technical Details
Return Value: | An int value, representing the rounded number. |
---|---|
Python Changelog: | Returns an int value in Python 3+, while it returns a float in Python 2. |