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 to0if 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
ndigitsis not specified. - The number rounded to
ndigitsdecimal places ifndigitsis 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