MakeCodingSimple
July 3, 2023

How To Round a Number With round() Function in Pyhton

Posted on July 3, 2023  (Last modified on July 11, 2023 )
2 minutes  • 281 words
Table of contents

How to round a number with round() function

In this tutorial we will learn about how to round a number in python with the round() function

Why do we add a string into a list?

Rounding numbers in Python allows us to simplify or adjust the precision of numerical values. When working with calculations or measurements, rounding can help us achieve a desired level of accuracy or present data in a more understandable format.

The round() function

The round() function in python is used for rounding number to a specified number of decimal places or to the nearest whole number if no decimal places are specified.

The round() function took two parameters:

Example Usage:

Example 1 : Without the number of digit

num = 12.7
rounded_num = round(num)
print(rounded_num)

Output:

13

Example 2 : With the number of digit

num = 7.43769
decimal_rounded_num = round(num, 2)
print(decimal_rounded_num)

Output:

7.44

Example 3 : Rounding to 0 decimal places

num = 4.8657
rounded_num = round(num)
print(rounded_num)

Output:

5

Conclusion:

In conclusion, the round() function in Python is a convenient tool for rounding numbers. It allows us to adjust precision by specifying the number of decimal places or rounding to the nearest whole number. The function takes two parameters: the number to be rounded and the desired decimal places (optional).


Share

 

Other Tutorial

 

Read Previous Read Next
How To Add A String To A List in Python How To Find The Biggest Number In A List In Python
Find Me in Social Media

Join our social media community and be part of the conversation! Follow us for inspiring content.