Python round() function
Python round() function
The round() function in Python returns a number rounded to ‘ndigits’ precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input.
Syntax
round(number[, ndigits])
Parameter
Number: This parameter represents the number to be rounded.
Digits: It is the optional parameter that represents the number of decimals to use when rounding the number.
Return
This function returns a floating point number after rounding off the specified number, with the specified number of decimals.
Example 1
# Python program explaining # the round() function roud_val = round(556.7543, 2) print("The round value: ",roud_val)
Output
The round value: 556.75
Example 2
# Python program explaining # the round() function print (" The ndigit+1 if the digit is =5") print(round(2.665, 2)) print("The ndigit+1 if the digit is >=5") print(round(2.676, 2)) print("The ndigit+1 if the digit is <5") print(round(2.673, 2))
Output
The ndigit+1 if the digit is =5 2.67 The ndigit+1 if the digit is >=5 2.68 The ndigit+1 if the digit is <5 2.67