Python Round Function

By | September 28, 2021
Python Round Function

In Python, we have many we have various data types such as int, float, str, etc. And for every data type, we have multiple in-built functions. One of those functions is round(), which return a rounded value for a floating-point number. 

Round Syntax

round(number, digits)

round() Parameters

The round() function can accepts two parameters.

  • The number which round value supposed to evaluate.
  • The digit parameter specifies the value up to which the number is supposed to round. By default, the digit value is 0.

Return value of round() function

  • For round(number) it would return the nearest rounded integer value.
  • For round(number, digit) it would return a floating-point rounded version of the number. The digit represents the number of decimals should be present in the returned number. By default, the digit value is zero which lead to 0 decimal number or integer.

round(number) Example

# if number is a float.
>>> round(20.1)

>>> round(20.4)

>>> round(20.5)

>>> round(20.6)

>>> round(20.9)
#if number is an integer
>>> round(20)

>>> round(21)
#if number is a string data type
>>> round("21.1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type str doesn't define __round__ method

<Note>: The round function only accepts int and float data type.

round(number, digit) Example

The digit parameter signifies the number of decimal digits up to which the specified number ti be round of.


>>> round(1.3333333, 1)

>>> round(1.33333, 2)

>>> round(1.3333333, 3)


  • round() function return the nearest rounded value for the specified number.
  • It accepts two parameters, the specified number and number of decimal digits.
  • the round() function accepts only integer and floating-point numbers.

People are also reading: 

Leave a Reply

Your email address will not be published.