Round Up in Python

Learn how to round up in Python using math.ceil(), decimal rounding, ceiling division, NumPy ceil(), and custom multiples. Understand why round() is not the same as rounding up and avoid common rounding mistakes.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

Round Up in Python

Rounding up means moving a number to the next greater integer or the next greater multiple. In Python, the standard way to round a number up to an integer is math.ceil(). Do not use round() when you specifically need always-upward rounding: round() rounds to the nearest value, and ties go to the even choice. For how integers and floats behave under the hood, see Python numbers.

This guide covers math.ceil(), ceiling division, rounding up to multiples of 5 or 10, decimal-place ceiling with Decimal, and numpy.ceil() for arrays. For a deeper look at the ceiling function itself, see Python ceil function.

Tested on: Python 3.13.3; kernel 6.14.0-37-generic.


Quick answer: round up in Python

Use math.ceil(number) to round up to the nearest integer. Do not use round() when you need always-upward rounding.

python
import math

print(math.ceil(3.1))
print(math.ceil(3.9))
Output

Both lines print 4. math.ceil(4.0) also prints 4 because the value is already an integer.


Python round up quick reference

Task Use
Round up to integer math.ceil(x)
Round up 3.1 to 4 math.ceil(3.1)
Round up division math.ceil(a / b)
Integer ceiling division -(-a // b)
Round up to nearest 10 math.ceil(x / 10) * 10
Round up to nearest 5 math.ceil(x / 5) * 5
Round up to 2 decimals Decimal with ROUND_CEILING or scale with math.ceil()
Round up NumPy array numpy.ceil(array)
Round to nearest value round(x)
Round down math.floor(x)

What does round up mean in Python?

Rounding up means moving to the nearest greater or equal value.

For positive numbers:

  • 3.1 rounds up to 4.
  • 3.9 rounds up to 4.
  • 4.0 stays 4.

For negative numbers, ceiling still moves toward positive infinity:

  • math.ceil(-3.1) returns -3 because -3 is greater than -3.1.

This behavior is called the ceiling. Python defines math.ceil(x) as the smallest integer greater than or equal to x.


Round up using math.ceil()

Import math, then call math.ceil(number). It returns an int and works with positive and negative numbers. This should be your first choice when you need upward rounding to an integer.

python
import math

print(math.ceil(3.1))
print(math.ceil(3.8))
print(math.ceil(4))
print(type(math.ceil(3.1)))
Output

The first three lines print 4, 4, and 4. The type line prints <class 'int'>.

python
import math

print(math.ceil(-3.1))
print(math.ceil(-3.7))
Output

Both lines print -3. The result moves toward positive infinity, not toward zero.


Why round() is not round up

round() rounds to the nearest value. Sometimes that means rounding down. When two values are equally close, Python rounds to the even choice.

python
print(round(3.2))
print(round(3.8))
print(round(2.5))
print(round(1.5))
print(round(0.5))
Output

This prints 3, 4, 2, 2, and 0. round(2.5) returns 2, not 3. round() is not suitable when you need always-upward rounding.

String formatting and round(num, 2) also round to nearest, not upward. Do not treat "{:.2f}".format(num) or round(num, 2) as ceiling operations.


round() vs math.ceil()

Function Meaning Example
round(x) Round to nearest round(3.2)3
math.ceil(x) Round upward math.ceil(3.2)4
math.floor(x) Round downward math.floor(3.8)3
int(x) Truncate toward zero int(3.8)3

Use math.ceil() for ceiling. Use round() only when nearest-value rounding is what you want. For rounding down, see Python floor function.


Round up division in Python

Use math.ceil(a / b) when you need enough pages, batches, chunks, or groups to cover a total.

python
import math

items = 43
per_page = 10

pages = math.ceil(items / per_page)
print(pages)
Output

This prints 5. Four full pages hold 40 items; the remaining 3 items need one more page.

For positive integers, integer ceiling division avoids floating-point division:

python
items = 43
per_page = 10

pages = -(-items // per_page)
print(pages)
Output

This also prints 5. The expression -(-a // b) applies floor division, then negates twice to get the ceiling of the quotient. The // operator is floor division; ** handles powers when you scale before ceiling.


Round up to nearest 10

Formula: math.ceil(number / 10) * 10.

python
import math

num = 457583
rounded_up = math.ceil(num / 10) * 10
print(rounded_up)
Output

This prints 457590.

round(number, -1) rounds to the nearest 10, not always upward:

python
num = 457583
print(round(num, -1))
print(math.ceil(num / 10) * 10)
Output

The first line prints 457580. The second prints 457590. Use math.ceil() when you need the next higher multiple of 10.


Round up to nearest 5

Formula: math.ceil(number / 5) * 5.

python
import math

print(math.ceil(11 / 5) * 5)
print(math.ceil(10 / 5) * 5)
Output

The first line prints 15 because 11 is not already a multiple of 5. The second prints 10 because 10 is already a multiple of 5.

5 * round(num / 5) rounds to the nearest multiple of 5, which can round down. Use math.ceil(num / 5) * 5 when you need the next higher multiple.


Round up to any multiple

General formula: math.ceil(number / multiple) * multiple.

python
import math

def round_up_to_multiple(number, multiple):
    return math.ceil(number / multiple) * multiple

print(round_up_to_multiple(4343, 5))
print(round_up_to_multiple(457583, 10))
print(round_up_to_multiple(1234, 100))
Output

This prints 4345, 457590, and 1300. The same pattern works for pricing tiers, page sizes, chunking, and grouping.


Round up to 2 decimal places

math.ceil() returns an integer. To round up to a fixed number of decimal places, scale up, apply ceiling, then scale back.

python
import math

x = 3.786847638
two_decimals = math.ceil(x * 100) / 100
print(two_decimals)
Output

This prints 3.79.

Binary floating-point can produce surprising decimal results. For example, 0.1 + 0.2 is not exactly 0.3 in IEEE-754 arithmetic. When exact decimal rounding matters, use Decimal.


Round up with Decimal

Use Decimal when you need exact decimal-place control. Pass an explicit rounding mode to quantize().

python
from decimal import Decimal, ROUND_CEILING, ROUND_UP

value = Decimal('3.786847638')
print(value.quantize(Decimal('0.01'), rounding=ROUND_CEILING))
Output

This prints 3.79.

For negative numbers, ROUND_CEILING and ROUND_UP can differ:

python
from decimal import Decimal, ROUND_CEILING, ROUND_UP

value = Decimal('-3.711')
print(value.quantize(Decimal('0.01'), rounding=ROUND_CEILING))
print(value.quantize(Decimal('0.01'), rounding=ROUND_UP))
Output

The first line prints -3.71 (toward positive infinity). The second prints -3.72 (away from zero). Choose the mode that matches your business rule.


Round up NumPy arrays using numpy.ceil()

Use numpy.ceil() for arrays. It applies ceiling element-wise and returns a floating array or scalar. Do not use numpy.round() when you need upward rounding.

python
import numpy as np

arr = np.array([1.1, 2.6, 4.6, 4.8, 10.0])
print(np.ceil(arr))
print(np.round(arr))
print(type(np.ceil(3.1)))
text
[ 2.  3.  5.  5. 10.]
[ 1.  3.  5.  5. 10.]
<class 'numpy.float64'>

np.ceil() returns [2., 3., 5., 5., 10.]. np.round() rounds to nearest, so 1.1 becomes 1.0 instead of 2.0. Install NumPy locally with pip install numpy if needed.

The NumPy documentation defines numpy.ceil() as returning the ceiling of the input element-wise, where the ceiling is the smallest integer i such that i >= x.


Round up negative numbers

math.ceil(-3.7) returns -3, not -4. Ceiling moves toward positive infinity, which surprises beginners who expect "up" to mean away from zero.

python
import math

print(math.ceil(-3.7))
print(math.ceil(-3.1))
Output

Both lines print -3.

If you need away-from-zero rounding for negatives, that is a different rule. Use Decimal with ROUND_UP, or apply math.ceil(abs(x)) with a sign only when your domain is non-negative.


Common mistakes when rounding up in Python

  • Using round() when math.ceil() is needed.
  • Expecting round(2.5) to return 3; Python returns 2 because ties round to even.
  • Assuming "{:.2f}" or round(num, 2) always rounds up.
  • Using numpy.round() instead of numpy.ceil() for upward array rounding.
  • Forgetting import math.
  • Treating ceiling as "away from zero" for negative numbers.
  • Using round(number, -1) or 5 * round(num / 5) when you need the next higher multiple.
  • Using integer floor division a // b without the -(-a // b) ceiling trick when you need a full extra unit for remainder.
  • Searching for a built-in roundup() function; Python does not provide one.
  • Misspelling NumPy as "nampy" in docs or imports.

Summary

Use math.ceil() to round up to an integer. Use math.ceil(x / multiple) * multiple to round up to a multiple of 5, 10, 100, or any other step. Use -(-a // b) for integer ceiling division on positive integers. Use math.ceil(x * 100) / 100 or Decimal with ROUND_CEILING when exact decimal-place rounding matters. Use numpy.ceil() for arrays. Do not use round() when you need always-upward rounding.


References


Frequently Asked Questions

1. How do you round up a number in Python?

Use math.ceil(number) after import math. It returns the smallest integer greater than or equal to the value.

2. Can you use round() to round up in Python?

No. round() rounds to the nearest value and ties go to the even choice, so it can round down. Use math.ceil() when you need always-upward rounding to an integer.

3. How do you round up division in Python?

Use math.ceil(a / b) for numeric values. For positive integers, -(-a // b) gives integer ceiling division without calling math.ceil().

4. How do you round up to the nearest 10 in Python?

Use math.ceil(number / 10) * 10. round(number, -1) rounds to the nearest 10, not always upward.

5. How do you round up to 2 decimal places in Python?

Scale up, apply ceiling, then scale back with math.ceil(x * 100) / 100, or use Decimal with ROUND_CEILING when exact decimal rounding matters.

6. What is the difference between ROUND_CEILING and ROUND_UP in Decimal?

ROUND_CEILING moves toward positive infinity. ROUND_UP moves away from zero. They differ for negative numbers such as -3.711 rounded to two decimals.
Bashir Alam

Data Analyst and Machine Learning Engineer

Computer Science graduate from the University of Central Asia, currently employed as a full-time Machine Learning Engineer at uExel. His expertise lies in OCR, text extraction, data preprocessing, and …