Python round() Function Explained
The built-in round() function returns a rounded version of a number.
You can use it in two common ways:
round(number)rounds to the nearest whole numberround(number, digits)rounds to a chosen number of decimal places
This is useful when you want cleaner numeric output or when you need to limit decimal places in a result.
Quick example
print(round(3.14159))
print(round(3.14159, 2))
Output:
3
3.14
Use round(number) to round to the nearest whole number, or round(number, digits) to keep a set number of decimal places.
What round() does
round()is a built-in Python function- It returns a rounded version of a number
- With one argument, it rounds to the nearest integer
- With two arguments, it rounds to a chosen number of decimal places
You do not need to import anything to use it.
Basic syntax
The syntax is:
round(number[, ndigits])
numberis the value to roundndigitsis optionalndigitscan be positive, zero, or negative
Basic examples:
print(round(7.8))
print(round(7.8, 1))
print(round(1234, -2))
Output:
8
7.8
1200
If you are still getting used to Python number types, see Python numbers explained: int, float, complex.
Using round() with one argument
When you pass only one argument, Python rounds to the nearest whole number.
print(round(4.2))
print(round(4.8))
Output:
4
5
With a normal float, the result is usually an integer:
result = round(10.2)
print(result)
print(type(result))
Output:
10
<class 'int'>
If you need to convert values directly to integers without rounding rules, compare this with Python int() function explained.
Using round() with decimal places
You can pass a second argument to control how many decimal places to keep.
print(round(3.14159, 2))
print(round(3.14159, 3))
Output:
3.14
3.142
This is helpful when you want a simpler numeric value for calculations or reporting.
price = 19.9876
rounded_price = round(price, 2)
print(price)
print(rounded_price)
Output:
19.9876
19.99
If you need to convert text such as "3.14159" before rounding, see how to convert a string to float in Python or Python float() function explained.
Using negative ndigits
A negative ndigits value rounds to tens, hundreds, or larger place values.
print(round(1234, -1))
print(round(1234, -2))
print(round(1234, -3))
Output:
1230
1200
1000
How this works:
-1rounds to the nearest 10-2rounds to the nearest 100-3rounds to the nearest 1000
This can be useful when you want less precise but easier-to-read numbers.
Important behavior beginners notice
Some results may look surprising with numbers ending in .5.
For example:
print(round(2.5))
print(round(3.5))
Output:
2
4
Python uses banker's rounding in tie cases. That means it rounds to the nearest even number in some .5 situations.
More examples:
print(round(1.5))
print(round(2.5))
print(round(3.5))
print(round(4.5))
Output:
2
2
4
4
This is normal Python behavior, not a bug.
So:
round(2.5)gives2round(3.5)gives4
If you expected .5 to always round upward, this behavior can be confusing at first.
Return values
round() returns the rounded value.
It does not change the original variable unless you save the result.
value = 3.14159
print(value)
print(round(value, 2))
print(value)
Output:
3.14159
3.14
3.14159
If you want to keep the rounded value, assign it:
value = 3.14159
value = round(value, 2)
print(value)
Output:
3.14
When to use round()
Use round() when you want to:
- Display simpler numeric output
- Limit decimal places in calculations
- Round values before reporting results
- Prepare numbers for easier reading
For example:
distance = 12.67891
print(round(distance, 2))
Output:
12.68
Common mistakes
Here are some common beginner mistakes when using round().
Expecting round() to always round .5 upward
This is one of the most common surprises.
print(round(2.5))
print(round(3.5))
Output:
2
4
Python may round tie values to the nearest even number.
Forgetting to save the returned value
round() returns a new value. It does not update the old one by itself.
value = 3.14159
round(value, 2)
print(value)
Output:
3.14159
To keep the rounded result:
value = round(value, 2)
Passing a string instead of a number
This will cause an error:
# print(round("3.14", 1))
You need to convert the string first:
text = "3.14"
number = float(text)
print(round(number, 1))
Output:
3.1
Confusing rounding a value with formatting text output
round() changes the numeric value it returns. It is not the same as formatting text for display.
If your data starts as text, convert it first with float() or int().
FAQ
Does round() always round 0.5 up?
No. In tie cases, Python may round to the nearest even number.
Does round() change the original number?
No. It returns a new value. You must assign it if you want to keep it.
Can round() round to tens or hundreds?
Yes. Use a negative ndigits value like -1 or -2.
Can I use round() on a string like "3.14"?
Not directly. Convert the string first with float() or int().