Python round function

Python round() function with EXAMPLES

Table of Contents

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

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.

Share this article
Subscribe
By pressing the Subscribe button, you confirm that you have read our Privacy Policy.
Need a Free Demo Class?
Join H2K Infosys IT Online Training
Enroll Free demo class