math.ceil() function Python (original) (raw)
Last Updated : 3 Jun, 2026
math.ceil() function returns the smallest integer greater than or equal to a given number. It always rounds a value upward to the nearest whole number. If the input is already an integer, the same value is returned.
This example shows how math.ceil() rounds a positive decimal number up to the next integer.
Python `
import math
x = 33.7 res = math.ceil(x) print(res)
`
Syntax
math.ceil(x)
- **Parameters: x - A numeric value (int or float).
- **Returns: smallest integer greater than or equal to x.
Examples
**Example 1: This example demonstrates how the function behaves with negative values. It still returns the smallest integer that is not less than the given number.
Python `
import math
a = -13.1 b = math.ceil(a) print(b)
`
**Explanation: math.ceil(-13.1) returns -13 because it is the smallest integer greater than or equal to -13.1.
**Example 2: This example applies math.ceil() to a list of decimal numbers and prints their ceiling values one by one.
Python `
import math
nums = [2.3, 7.01, 101.96] res = [math.ceil(n) for n in nums] print(res)
`
**Explanation: math.ceil(n) rounds each value in nums upward 2.3 -> 3, 7.01 -> 8, 101.96 -> 102.