The syntax of
round() function takes two parameters:
- number - the number to be rounded
- ndigits (optional) - number up to which the given number is rounded; defaults to 0
Return value from round()
round()returns the nearest integer to the given number.
round()returns the number rounded off to the
Example 1: How round() works in Python?
# for integers print(round(10)) # for floating point print(round(10.7)) # even choice print(round(5.5))
10 11 6
Example 2: Round a number to the given number of decimal places
print(round(2.665, 2)) print(round(2.675, 2))
In the program, you may think 2.675 should have been rounded to 2.68. This isn't a bug. This is considered the standard rounding method these days.