Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Function

round

round() rounds a number to a selected decimal precision, or to the nearest integer when ndigits is omitted. Ties for built-in numeric types use round-half-to-even.

How it works

round() returns a number rounded to a requested decimal precision. Without ndigits, or when it is None, it returns the nearest integer; otherwise the result normally retains the type of number, and custom objects can define the operation through __round__().

Syntax

round(number, ndigits=None)

Parameters

NameTypeDescription
numbernumberNumber to round; the documentation names this argument number.
ndigitsint | NoneOptional integer precision after the decimal point; positive, zero, and negative integers are valid, and None has the same effect as omission.

Returns

The nearest integer when ndigits is omitted or None; otherwise the rounded value, generally with the same type as number.

Key points

  • Use ndigits to choose how many decimal places of precision to retain.
  • Leaving ndigits out, or passing None, produces the nearest integer.
  • ndigits accepts positive, zero, and negative integers, enabling finer or coarser rounding.
  • The no-precision form returns an int rather than preserving the input's numeric type.
  • With an ndigits value, the result keeps number's type for the documented built-in types.
  • Custom objects can define their rounding behavior by implementing __round__().

Common mistakes

  • Binary floating-point representation can make a seemingly exact decimal produce an unexpected rounded result, such as round(2.675, 2) producing 2.67.
  • Ties use round-half-to-even rather than always rounding away from zero; for example, round(1.5) is 2 while round(0.5) is 0.

Example: Rounding numbers

print(round(2.675, 2))
print(round(1.5))
print(round(25, -1))

Demonstrates decimal-place rounding, ties-to-even behavior, and negative precision.

When to use it

Format calculated precision

Presenting measurements or computed values with a fixed number of decimal places.

Coarsen numeric values

Reducing a value to tens, hundreds, or other powers of ten with negative ndigits.

Round custom numeric objects

Supporting domain-specific numeric classes that need customized rounding.

Interview questions

QWhat does round() do when ndigits is omitted?

round(number, ndigits=None) rounds number to the requested decimal precision. If ndigits is omitted or None, the result is the nearest integer.

Follow-up: What happens for a tie? The built-in types choose the nearest multiple, and an equally close tie is resolved toward the even choice.

QWhat values are valid for ndigits?

ndigits may be any integer, including positive, zero, or negative values. Negative values round to coarser powers of ten, such as round(25, -1) producing 20.

Follow-up: Does ndigits have to be nonnegative? No; the documentation explicitly permits positive, zero, and negative integers.

QWhat type does round() return?

When ndigits is omitted or None, round() returns an integer. Otherwise, its return type is the same as number for the built-in types that support it, and general objects can provide __round__().

Follow-up: How can a custom numeric type control rounding? It implements __round__, which round() delegates to for a general object.

  • __round__
  • int
  • float

Source: Built-in functions. Checked 2026-10-15.