English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The round() function returns a floating-point number rounded to the specified decimal place.
The syntax of round() is:
round(number, ndigits)
round() function has two parameters:
number -The number to be rounded
ndigits (optional) -The number rounded to the given number; default is 0
If ndigits is not provided, round() returns the nearest integer to the given number.
If ndigit is given, round() returns the number rounded to ndigit.
# Number is an integer print(round(10)) # Number is a floating-point number print(round(10.7)) # Number is a floating-point number print(round(5.5))
Output result
10 11 6
print(round(2.665, 2)) print(round(2.675, 2))
Output result
2.67 2.67
In the program, you may think2.675It should be rounded to2.68This is not a bug. It is considered a standard rounding method.