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, a TypeError is returned.
Return Value
Returns an integer representing the rounded number.
Example
The following example returns values rounded up to the nearest integer:
Example
Import the math package
import
math
Output the values rounded up to the nearest integer
(
math
.
ceil
(
1.4
)
)
(
math
.
ceil
(
5.3
)
)
(
math
.
ceil
(
5.3
)
)
(
math
.
ceil
(
22.6
)
)
(
math
.
ceil
(
10.0
)
)
Output result:
2
6
-5
23
10
Python math Module