round()

Rounds a number to the given number of decimal places.

Returns
The rounded number.
On this page

Example

#
Python
print(round(81.666, 1))
print(round(81.666))
print(round(2.5), round(3.5))
print(round(1234, -2))
Resultsaved result, you can check it
81.7
82
2 4
1200

Definition and usage

#

The round(number, ndigits) function rounds to the given number of decimal places. Without the second argument, it returns an integer.

Python uses banker's rounding: values exactly halfway round to the nearest even number. round(2.5) gives 2, and round(3.5) gives 4. That reduces systematic bias across many roundings.

Because of floating-point imprecision, round(2.675, 2) gives 2.67, since 2.675 is stored in memory as a value slightly smaller than that. For exact financial calculations, use the decimal module.

Syntax

#
Syntax
round(number)
round(number, ndigits)

Parameters

#
  • number

    int | float

    The number to round.
  • ndigits

    int, optional

    The number of decimal places. A negative value rounds to tens, hundreds, and so on.

Good practices

#
  • To display a number with a fixed number of decimal places, an f-string is more convenient: f"{x:.2f}".
  • Remember banker's rounding for values ending in .5.

Related entries

#

Spotted a mistake or missing an example? Write to us.