round
Round a number to the given number of decimal places.
Python 3.13
round(number, ndigits=None)- =default value
- number
- The number to round.int | float
- ndigits
- How many decimal places to keep, rounding to an integer by default; a negative value rounds to tens, hundreds and so on.int | NoneOptional
Return value
An int if ndigits is omitted or None, otherwise a number of the same type as number.
Examples
Rounding to two decimal places
Python 3.13
print(round(3.14159, 2))3.14
Halves round to even
Python 3.13
print(round(2.5), round(3.5))2 4
Rounding to hundreds
Python 3.13
print(round(1234, -2))1200
Details
Halves are rounded to the nearest even number: round(2.5) gives 2, and round(3.5) gives 4. Because fractions are stored in binary, round(2.675, 2) gives 2.67, not 2.68.
