Built-in Functions and Types

round()

Round a numeric value at a specified decimal position. Ordinary int and float ties select the even candidate; a float may lie slightly above or below the decimal tie because its representation is approximate. Negative ndigits rounds to tens, hundreds and so on. Custom objects can implement __round__().

Formal Syntax & Structure

python syntaxpython
round(number, ndigits=None)

Parameters & Attributes

NameTypeDescription
numbernumber or object supporting __round__Value to round.
ndigitsint | NoneDecimal-place position; None or omission requests the nearest integer for ordinary int/float.

Return Value

number

For ordinary int or float, int when ndigits is omitted or None; otherwise the same numeric type. Custom objects determine their result.

Working Example

Example Snippetpython
print(round(4.5))print(round(5.5))print(round(1847, -2))
Python Reference