In Python, the round()
function rounds a number off to the specified decimal place. The value returned by the function is a floating point.
round(number, decimals)
number
: The actual number which needs to be rounded; it is a compulsory argument.
decimals
: The number of decimal places to be rounded to; it is an optional argument.
By default, the number is rounded to 0
decimal places unless specified otherwise in the decimals
argument.
num = 5.4739# The default callprint(round(num))# Specified decimal placeprint(round(num, 2))# More decimal places than the number containsprint(round(num, 8)) # Original number returned
Free Resources