math.ceil
Round a number up to the nearest integer.
Python 3.13
math.ceil(x)- x
- The number to round.int | float
Return value
An int.
Examples
Rounding up
Python 3.13
import math
print(math.ceil(4.2))5
Rounding up a negative number
Python 3.13
import math
print(math.ceil(-4.8))-4
Details
It returns an int, not a float: math.ceil(4.0) gives 4. For negative numbers, "up" means toward zero: math.ceil(-4.8) is -4. To divide integers rounding up without float, use -(-a // b).
