round()

round(number[, ndigits])
Returns: int | float · Added in v3.0 · Updated March 13, 2026 · Built-in Functions
built-in numbers math precision

The round() function returns a number rounded to a given number of decimal places. If ndigits is omitted, it returns an integer. Python uses banker’s rounding (round half to even), which rounds 0.5 to the nearest even number instead of always rounding up.

Syntax

round(number)
round(number, ndigits)

Parameters

ParameterTypeDefaultDescription
numberint | floatThe number to round. Can be an integer, float, or any object implementing __round__(). Position-only.
ndigitsintNoneThe number of decimal places to round to. Can be negative to round to powers of 10. Optional.

Returns: An integer if ndigits is omitted, otherwise a float rounded to the specified precision.

Examples

Basic rounding to integers

# Round to nearest integer
print(round(3.7))
# 4

print(round(3.3))
# 3

# Negative numbers work the same way
print(round(-2.5))
# -2

print(round(-2.7))
# -3

Banker’s rounding (round half to even)

Python rounds 0.5 to the nearest even number:

# 2.5 rounds to 2 (even)
print(round(2.5))
# 2

# 3.5 rounds to 4 (even)
print(round(3.5))
# 4

# 4.5 rounds to 4 (even)
print(round(4.5))
# 4

# 5.5 rounds to 6 (even)
print(round(5.5))
# 6

Rounding to decimal places

# Round to 1 decimal place
print(round(3.14159, 1))
# 3.1

# Round to 2 decimal places
print(round(3.14159, 2))
# 3.14

# Round to 3 decimal places
print(round(3.14159, 3))
# 3.142

Negative ndigits for rounding to powers of 10

# Round to nearest hundred
print(round(1234, -2))
# 1200

# Round to nearest thousand
print(round(5678, -3))
# 6000

# Round to nearest ten
print(round(47, -1))
# 50

Common Patterns

Currency formatting

# Format price to 2 decimal places
price = 19.99
tax_rate = 0.08
total = round(price * tax_rate, 2)
print(total)
# 1.6

# Better approach: use decimal module for money
from decimal import Decimal
price = Decimal("19.99")
total = (price * Decimal("0.08")).quantize(Decimal("0.01"))
print(total)
# 1.59

Display formatting

# Pretty print numbers in a table
data = [1.23456, 9.87654, 0.12345]
for value in data:
    print(f"{round(value, 2):>8}")
#     1.23
#     9.88
#     0.12

Precision control in calculations

# Cumulative floating point errors
result = 0.0
for i in range(10):
    result += 0.1

print(result)
# 0.9999999999999999

# Round to fix display
print(round(result, 2))
# 1.0

Grouping large numbers

# Round large numbers to nearest million
population = 1234567890
print(round(population, -6))
# 1234000000

# Round to nearest thousand
print(round(1234567, -3))
# 1235000

Errors

TypeError for non-numeric types

# String raises TypeError
round("3.5")
# TypeError: type str doesn't define __round__ method

# Complex numbers raise TypeError
round(3 + 4j)
# TypeError: type complex doesn't define __round__ method

ValueError with custom objects

Objects that implement __round__() but return the wrong type:

class BrokenNumber:
    def __round__(self, ndigits=None):
        return "not a number"

round(BrokenNumber())
# TypeError: __round__ returned non-Integral type

See Also