The round() function

print(round(3.14159, 2))   # 3.14
print(round(7.8))          # 8

With no decimal-place argument, round() returns the nearest integer.

Always round down or up

import math
print(math.floor(7.8))   # 7  (down)
print(math.ceil(7.2))    # 8  (up)

Use math.floor and math.ceil when you need a fixed direction rather than nearest.

Round for display with an f-string

price = 19.5
print(f"{price:.2f}")   # 19.50

This keeps trailing zeros, which round() drops, so it is ideal for showing prices.

Common mistakes

  • Expecting round(2.5) to be 3. Python uses banker’s rounding, so round(2.5) is 2 and round(3.5) is 4 — it rounds to the nearest even number on a tie.
  • Using round() for money. Floats are imprecise; for currency use the decimal module or format with an f-string for display.

Frequently asked questions

Why does round(0.5) return 0?

Python rounds half-to-even (banker’s rounding) to reduce bias over many values, so a tie goes to the nearest even number.

How do I round to the nearest 10 or 100?

Pass a negative number of digits: round(1234, -2) gives 1200.

Want a solid grasp of numbers and math in Python? Try our free Python course with live examples.