Skip to main content

round()

The round() function in Python is a built-in function that returns the floating-point number rounded to a specified number of digits after the decimal point. It takes two arguments: the number to be rounded and the number of digits to round to. If the number of digits is not provided, it defaults to 0, rounding to the nearest integer value.

Parameter Values

Parameter Description
number

The number to be rounded.

ndigits

The number of digits up to which the number is to be rounded. Defaults to 0 if not provided, indicating rounding to the nearest integer.

Return Values

The round() function in Python returns an int or a float.

How to Use round() in Python

Example 1:

Return the floating point number x rounded to n digits after the decimal point. If n is omitted, it returns the nearest integer to x.

round(3.14159, 2)
Example 2:

When two multiples are equally close, rounding is done toward the even choice. 1.5 and 2.5 are both equally close to 2.0, but 2.5 rounds to 2.0.

round(2.5)
Example 3:

If the number of digits given is negative, it will round off to the closest 10, 100, 1000, etc.

round(12345, -2)