math

round()

Rounds a number to ndigits decimal places. When ndigits is None (default), returns an int rounded to nearest integer using banker's rounding.

round(number, ndigits=None)

Parameters

Parameter Purpose
number Value to round
ndigits Decimal places (negative rounds to tens/hundreds); None returns int

Examples

round(3.7)

Returns 4 (int)

round(2.5)

Returns 2 (banker's rounding — nearest even)

round(3.14159, 2)

Returns 3.14

round(1234, -2)

Returns 1200

Gotcha

Uses banker's rounding (round-half-to-even) — round(0.5) is 0, round(2.5) is 2. Also affected by float representation: round(2.675, 2) returns 2.67.

Related built-ins

← All Python built-ins