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))
print(math.ceil(10.0))
Try it Yourself »
Definition and Usage
The math.ceil()
method rounds a number UP to the nearest integer, if necessary, and returns the result.
Tip: To round a number DOWN to the nearest integer, look at the
math.floor()
method.
Syntax
math.ceil(x)
Parameter Values
Parameter | Description |
---|---|
x | Required. Specifies the number to round up |
Technical Details
Return Value: | An int value, representing the rounded number. |
---|---|
Change Log: | Python 3+ : Returns an int valuePython 2.x : Returns a float value. |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.