In Python, math.ceil() always rounds UP to the next integer, regardless of the decimal value. This is the "ceiling" function.
import math
math.ceil(number)
Returns the next whole number
import math
math.ceil(3.1) # 4
math.ceil(3.5) # 4
math.ceil(3.9) # 4
math.ceil(12.01) # 13
import math
# Example 1: Calculate boxes needed
items = 47.3
boxes_needed = math.ceil(items)
print(boxes_needed) # 48
# Example 2: Calculate pages needed
total_items = 127
items_per_page = 10
pages = math.ceil(total_items / items_per_page)
print(pages) # 13
# Example 3: Round up to nearest 5
value = 23
rounded_to_5 = math.ceil(value / 5) * 5
print(rounded_to_5) # 25
| Value | math.ceil() | round() | math.floor() |
|---|---|---|---|
| 3.1 | 4 | 3 | 3 |
| 3.5 | 4 | 4 | 3 |
| 3.9 | 4 | 4 | 3 |
Always rounds UP
Standard rounding
Always rounds DOWN
items = 47.3
boxes = math.ceil(items)
# 48 boxes
total = 127
per_page = 10
math.ceil(127/10) = 13
staff_needed = 5.3
hired = math.ceil(staff_needed)
# 6 people
boards = 23.2
order = math.ceil(boards)
# 24 boards
import math
math.ceil(number)
ANY decimal rounds UP
Inventory, people, materials