All IT Courses 50% Off
Python Tutorials

Python round() function with EXAMPLES

The round() function is one of the built-in functions in Python. This function is used to round the decimal points to the user-specified number. If the user does not give input, then the round function converts the float into an integer.

Let’s take a look at code.

Rounding Integer Value

num = 5.2234232
print(round(num))

The following is the output.

Rounding Integer Value

Round function to a specified number.

The first input to the Python round function is the number that the user wants to round. The second input is the number of digits the user wants after the decimal point.

num = 5.1234567
print(round(num,2))
print(round(num,3))
print(round(num,4))

The following is the output of the above code.

Round function

Rounding Negative Values

Rounding negative values is the same as a positive value.

m = -5.1234567
print(round(num))
print(round(num,2))
print(round(num,3))
print(round(num,4))
Rounding Negative Values

Rounding Integer

When we try to round integer, the result remains the same. Let’s have a look at the code.

num = 4
print(round(num))
print(round(num,2))
print(round(num,3))
print(round(num,4))
Rounding Integer

Facebook Comments
Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close