Python round function with example

Spread the love

Python round :

This function is used to return the rounded value.

Syntax : round(value, n)

value – the value you are going to rounded.

n – the value for n is zero, you can specify the number of decimal to round.

For one decimal value

Example: 

Code:

round(12)

round(12.5)

round(12.4)

round(12.7)

Output:

print(“round value for 12:”, round(12))

print(“round value for 12:”, round(12.5))

print(“round value for 12:”, round(12.4))

print(“round value for 12:”, round(12.7))

For multiple decimals:

print(“round value for 12 with one decimal :”, round(12.5555, 1))
print(“round value for 12 with two decimal:”, round(12.5555, 2))
print(“round value for 12 with three decimal:”, round(12.5555, 3))
print(“round value for 12 with four decimal:”, round(12.5555, 4))

Output:

round value for 12 with one decimal : 12.6
round value for 12 with two decimal: 12.56
round value for 12 with three decimal: 12.556
round value for 12 with four decimal: 12.5555

admin

admin

Leave a Reply

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