Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
round
floating point

What is the round() function in Python?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring