How to Round a Number in Python with round
A price of 3.14159 reads better as 3.14. Python's built-in round does that: give it a number and how many decimal places to keep. It has one rule that surprises people, which this guide shows too, with real output from Python 3.15.2.
Syntax
round(<number>, <decimal places>)
round(<number>)
| Part | What it means |
|---|---|
<number> | The number to round |
<decimal places> | Optional. How many digits to keep after the decimal point. Without it, you get a whole number |
The built-in functions reference: "Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input."
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
price = 3.14159
print(round(price, 2))
print(round(price))
print(round(2.5))
print(round(3.5))

Step 2: Run It
uv run python rounding.py
3.14
3
2
4

Two decimal places gave 3.14, and no decimal places gave 3. 2.5 became 2 but 3.5 became 4: a number exactly halfway goes to the even neighbor. The reference: "if two multiples are equally close, rounding is done toward the even choice".
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Expecting halves to always round up | round(2.5) gave 2 | That's the rule for exact halves; for money, see decimal below |
Expecting round(2.675, 2) to give 2.68 | It gave 2.67: the float stored for 2.675 is 2.67499999999999982236 | Use the decimal module when exact decimal digits matter |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A rounded value looks one digit off | Binary floats can't store most decimal fractions exactly | Print it with f"{value:.20f}" to see the stored value |
FAQ
Does round give an int or a float?
Without decimal places, an int; with them, a float: type(round(3.7)) was <class 'int'> and type(round(3.7, 1)) was <class 'float'>.
Can I round to tens or hundreds?
Yes, with a negative number of places: round(1234, -2) gave 1200.
Conclusion
round(price, 2) gave 3.14 and round(price) gave 3. Halfway values go to the even neighbor, and floats can make a value sit just below the halfway point.
Additional Resources
- round() — the function and its note on floats.
- Floating-point arithmetic: issues and limitations — why
2.675isn't stored exactly.
