Python round() Function



Python round() is a built-in function in Python. It returns x rounded to n digits from the decimal point.

Syntax

Following is the syntax for the round() function −

round(x [, n])

Parameters

  • x − This is a numeric expression.

  • n − Represents number of digits from decimal point up to which x is to be rounded. Default is 0.

Return Value

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

Example

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

print ("round(70.23456) : ", round(70.23456))
print ("round(56.659,1) : ", round(56.659,1))
print ("round(80.264, 2) : ", round(80.264, 2))
print ("round(100.000056, 3) : ", round(100.000056, 3))
print ("round(-100.000056, 3) : ", round(-100.000056, 3))

When we run the above program, it produces the following output

round(70.23456) : 70
round(56.659,1) : 56.7
round(80.264, 2) : 80.26
round(100.000056, 3) : 100.0
round(-100.000056, 3) : -100.0
python_built_in_functions.htm
Advertisements