← Back to Home

How to Round Up in Python

Use math.ceil() to always round UP in Python

The math.ceil() Function

In Python, math.ceil() always rounds UP to the next integer, regardless of the decimal value. This is the "ceiling" function.

math.ceil() Syntax

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

Step-by-Step Guide

Step 1: Import the math Module

import math

Step 2: Call math.ceil() with Your Number

result = math.ceil(47.3)

Step 3: Use the Rounded Result

print(result) # Output: 48

Complete Examples

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

math.ceil() vs round() vs math.floor()

Valuemath.ceil()round()math.floor()
3.1433
3.5443
3.9443

math.ceil()

Always rounds UP

round()

Standard rounding

math.floor()

Always rounds DOWN

Real-World Use Cases

📦 Inventory

items = 47.3

boxes = math.ceil(items)

# 48 boxes

📄 Pagination

total = 127

per_page = 10

math.ceil(127/10) = 13

👥 Staffing

staff_needed = 5.3

hired = math.ceil(staff_needed)

# 6 people

🏗️ Materials

boards = 23.2

order = math.ceil(boards)

# 24 boards

Quick Reference

📋 Import

import math

⬆️ Round Up

math.ceil(number)

💡 Remember

ANY decimal rounds UP

📦 Best For

Inventory, people, materials