In python, there is a built in function for rounding off number. The function round() rounds off the given the number and returns a floating number.
round(number, number of digits)
- number – number to be rounded.
- number of digits – rounds off to the given number of digits. If this is not provided,
- if only an integer is given, then it will round off to the same integer.
- if a decimal number is given, then it will round off to the ceil integer after that if the decimal value has >=5, and it will round off to the floor integer if the decimal is <5.
print(round(7)) print(round(7.5)) print(round(7.4)) print(round(7.7)) print(round(7.3254,2)) print(round(7.3254,3))
7 8 7 8 7.33 7.325
Work out more examples on your own for better understanding.