Python has a built-in round() function that takes two numeric arguments, number and ndigits, and returns a floating point number that is a rounded version of the number up to the specified number of decimals.
The default number of decimal is 0, meaning that the function will return the nearest integer.
The round() function in Python will round to the nearest whole number and ‘rounding to the even number’ when equidistant, meaning that exactly 12.5 rounds to the integer 12.
# For integersx=12print(round(x))# For floating pointx=12.3print(round(22.7)) # if the second parameter is present# when the (ndigit+1)th digit is =5 x=4.465print(round(x, 2)) # when the (ndigit+1)th digit is >=5 x=4.476print(round(x, 2)) # when the (ndigit+1)th digit is <5 x=4.473print(round(x, 2))