What is the round() function in Python?

In Python, the round() function rounds a number off to the specified decimal place. The value returned by the function is a floating point.

Syntax

round(number, decimals)
  • number: The actual number which needs to be rounded; it is a compulsory argument.

  • decimals: The number of decimal places to be rounded to; it is an optional argument.

By default, the number is rounded to 0 decimal places unless specified otherwise in the decimals argument.

svg viewer

Example

num = 5.4739
# The default call
print(round(num))
# Specified decimal place
print(round(num, 2))
# More decimal places than the number contains
print(round(num, 8)) # Original number returned

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved