Trusted answers to developer questions

What is the round() function in Python?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

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

RELATED TAGS

python
round
floating point
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?