Python round()
is a built-in function that returns the rounded off floating point number to specified digits after the decimal point. If not specified explicitly, round()
returns rounded off floating point number to the nearest integer to its input.
round (number[, decimalplaces])
round()
function takes two parameters as arguments.
Note: round()
function sometimes doesn’t exactly returns the rounded number as we expect in mathematics. For example, round(2.675, 2)
gives 2.67
instead of the expected 2.68
. This is because in Python some decimal numbers cannot be represented exactly as a float.
>>> #in absence of decimalplaces
>>> round(1)
1
>>> round(1.4)
1
>>> round(1.6)
2
>>> #with decimal places
>>> round(1.343,2)
1.34
>>> round(1.346,2)
1.35