The round() method in Python number returns x rounded to the n digits from a specific decimal point. This round() method in Python is its another inbuilt function that returns you with a float number which is rounded to the closest decimal places and is given as input. However, in case the decimal places that are to be rounded aren’t specified then it would be considered as zero and would be rounded to the nearest integer.
Following is the syntax for round() method:
round( x [, n] )
This method returns x rounded to n digits from the decimal point.
The following example shows the usage of round() method.
print "round(80.23456, 2) : ", round(80.23456, 2)
print "round(100.000056, 3) : ", round(100.000056, 3)
print "round(-100.000056, 3) : ", round(-100.000056, 3)
When we run above program, it produces following result:
round(80.23456, 2) : 80.23
round(100.000056, 3) : 100.0
round(-100.000056, 3) : -100.0
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.