round(x) with no second argument rounds to the nearest integer and returns an int; round(x, n) rounds to n decimal places and returns a float. Python uses round-half-to-even for exact ties, meaning a value exactly halfway between two integers rounds toward whichever is even — this reduces statistical bias compared to always rounding up, but it surprises people used to the classic-rounding convention taught in school.
1Understanding round()
round(x) with no second argument rounds to the nearest integer and returns an int; round(x, n) rounds to n decimal places and returns a float. Python uses round-half-to-even for exact ties, meaning a value exactly halfway between two integers rounds toward whichever is even — this reduces statistical bias compared to always rounding up, but it surprises people used to the classic-rounding convention taught in school.
round() operates on the actual binary value of a float, so rounding a value like 2.675 to 2 decimal places can give an unexpected result, because that value isn't exactly representable in binary — this is a floating-point precision issue, not a bug in round() itself.
print(round(3.14159, 2))
print(round(7.5))
print(round(2.5))2Practical Example
Here is a real-world application of round() showing how it is used in production Python code.
from decimal import Decimal, ROUND_HALF_UP
price = Decimal("2.675")
rounded = price.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
print(rounded)3Best Practices
Follow these guidelines when working with round():
1. Use the decimal module with ROUND_HALF_UP instead of round() when you need classic, predictable rounding, such as for money
2. Remember round(x, n) still returns a float, which can carry the same floating-point representation quirks as any other float
3. Don't assume round() always rounds a tie upward — verify behavior on ties if it matters for your use case
Tip: round() operates on the actual binary value of a float, so rounding a value like 2.675 to 2 decimal places can give an unexpected result, because that value isn't exactly representable in binary — this is a floating-point precision issue, not a bug in round() itself.
print(round(3.14159, 2))
print(round(7.5))
print(round(2.5))