If you want to round a number to a whole number or to a few decimal places, the Python round function is what you’re looking for. It takes a number and an optional digit count, and gives you back the closest value.
print(round(3.14159, 2))
# 3.14
In this tutorial, I’ll take round() through whole numbers, decimal places, tens and thousands, ties, money and lists. Every one ran in Python 3.12.5 in VS Code.
Python round() Syntax
round(number, ndigits=None)
| Parameter | Required | Default | Description |
|---|---|---|---|
number | Yes | none | An int, float, Decimal or any object with __round__() |
ndigits | No | None | Digits after the decimal point; zero and negative integers work too |
Return value: an int without ndigits; otherwise the input’s type.
Note: there’s no math.round(). round() is a built-in, and the Python math module gives you floor(), ceil() and trunc() for a fixed direction.
When to Use round() in Python
- Prices, taxes and totals in dollars and cents
- Long float results before printing
- Counts rounded to hundreds or thousands
- Averages rounded to one decimal
Need to always round up or down? See how to round numbers in Python.
Example 1: Round a Number to the Nearest Integer
Let me start with no second argument:
print(round(3.7))
print(round(7.3))
print(round(-4.6))
print(type(round(3.7)).__name__)
Output:
4
7
-5
int

How does this work? with one argument, round() returns the closest whole number as an int, so -4.6 became -5.
Example 2: How to Round in Python to Decimal Places
Pass ndigits to keep that many digits after the point. This is what people mean by round off in Python:
price = 1234.5678
print(round(price, 2))
print(round(3.14159, 3))
print(round(19.96, 1))
print(round(42, 2))
Output:
1234.57
3.142
20.0
42

How does this work? round(19.96, 1) gave 20.0, a float, and the int 42 came back unchanged. More cases: rounding numbers to 2 decimal places in Python.
Example 3: Round to Tens, Hundreds or Thousands
A negative ndigits rounds left of the decimal point:
visitors = 48_731
print(round(visitors, -2))
print(round(visitors, -3))
print(round(1_284_950.75, -4))
Output:
48700
49000
1280000.0
How does this work? -2 rounds to the nearest hundred, -3 to the nearest thousand. A float stays a float.
Example 4: Rounding in Python with Ties and Floats
This part surprises most people:
from decimal import Decimal, ROUND_HALF_UP
print(round(0.5), round(1.5), round(2.5), round(-0.5))
print(round(2.675, 2))
amount = Decimal("2.675")
print(amount.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP))
Output:
0 2 2 0
2.67
2.68

How does this work? a halfway value goes to the even neighbor, so 2.5 rounds to 2. And 2.675 is stored as 2.67499…, so it rounds down (see floating-point numbers in Python). Decimal gives 2.68.
Example 5: Round an Order Total with Sales Tax
Here’s a cart total with the Python sum() function and Texas sales tax:
items = [19.99, 34.50, 7.25, 112.89]
subtotal = sum(items)
tax = subtotal * 0.0825 # 8.25% Texas sales tax
print(tax)
print(round(tax, 2))
print(round(subtotal + tax, 2))
Output:
14.406975000000001
14.41
189.04

How does this work? round(…, 2) trimmed the raw tax and the total to cents. To add a dollar sign and commas, see formatting numbers as currency in Python.
Example 6: Round Every Number in a List
A list comprehension rounds each reading:
temps = [41.236, 38.71, 45.0, 43.649, 39.982]
print([round(t, 1) for t in temps])
avg = sum(temps) / len(temps)
print(round(avg, 1))
print(round(2.50, 2), f"{2.50:.2f}")
Output:
[41.2, 38.7, 45.0, 43.6, 40.0]
41.7
2.5 2.50
How does this work? each reading and the average got one decimal. round(2.50, 2) prints 2.5, so for 2.50 use an f-string with :.2f.
Pro Tip: for NumPy arrays, use numpy.round().
round() vs int() vs math.floor() vs math.ceil()
| Call | 3.7 | -3.7 | Rule |
|---|---|---|---|
round(x) | 4 | -4 | Nearest, ties to even |
int(x) | 3 | -3 | Drops the decimals |
math.floor(x) | 3 | -4 | Always down |
math.ceil(x) | 4 | -3 | Always up |
Direction matters? Use the Python floor() function or Python ceil() function.
Common Mistakes with Python round()
for args in (("3.7",), (3.7, 1.5), (None,)):
try:
round(*args)
except TypeError as err:
print("TypeError:", err)
Output:
TypeError: type str doesn't define __round__ method
TypeError: 'float' object cannot be interpreted as an integer
TypeError: type NoneType doesn't define __round__ method

- Convert strings with
float()first. ndigitsmust be an integer.- Check for
Nonebefore rounding.
Wrapping Up the Python round() Function
Python’s round() function rounds to the nearest integer or to any digit count, with ties to even. Next, browse more Python built-in functions and methods.
More number practice:
- print 2 decimal places in Python
- convert a float to an int in Python
- get the decimal part of a number in Python
- remove trailing zeros from a decimal
Python round() Function: Common Questions
How do you use the round function in Python?
Call round(x) for a whole number or round(x, 2) for two decimal places.
Why does round(2.5) return 2 in Python?
Python uses round half to even (banker’s rounding), which avoids upward bias in totals.
Does round() change the original variable?
No. Assign the result: price = round(price, 2).
How do I round half up in Python?
Use Decimal.quantize() with ROUND_HALF_UP, as in Example 4.
Can round() return a float with no decimals?
Yes. round(7.6, 0) returns 8.0 because ndigits was given.