Python Number round() Method


Advertisements


Description

The method round() returns x rounded to n digits from the decimal point.

Syntax

Following is the syntax for round() method −

round( x [, n]  )

Parameters

  • x − This is a numeric expression.

  • n − This is also a numeric expression.

Return Value

This method returns x rounded to n digits from the decimal point.

Example

The following example shows the usage of round() method.

Live Demo
#!/usr/bin/python

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

python_numbers.htm

Advertisements