round(number, ndigits=None)

Returns a floating-point number rounded to the specified number of decimal places.

Parameters

  • number: Number to be rounded.
  • ndigits: Number of decimal places to round to. Defaults to 0 if not specified.

For built-in types that support the function, values are rounded to the nearest multiple of 10 to the power of minus ndigits. If two multiples are equally close, rounding is towards the even choice. For example, both round(0.5) and round(-0.5) are 0, but round(1.5) is 2.

Return Value

The round() function returns:

  • The nearest integer to the given number if ndigits is not specified.
  • The number rounded to ndigits decimal places if ndigits is specified.

Examples

# For integers
print(round(12))

# For floating-point numbers
print(round(9.7))

# Rounding choice
print(round(5.5))

# Result

12
10
6