In this python if else program, we will round up the number to 2 decimal places if the number is a float.
Float number:
A float is a floating-point number, which means it is a number that has a decimal place. Floats are used when more precision is needed.
Steps to solve the program
- Take a number as input.
- Using an if-else statement check the type of the number using type().
- If the type of the number is a float then round up the number to 2 decimal places using the round() function.
- Else print the number as it.
num = 25.3614
if type(num) == float:
print(round(num,2))
else:
print(num)
Output :
25.36
Related Articles
Python program to check whether the input number is divisible by 12 or not.
Python program to check whether the input number is a square of 6 or not.
Python program to check whether the input number is a cube of 3 or not.
Python program to check whether two numbers are equal or not.
Python program to check whether the given input is a complex type or not.
Python program to check whether the given input is Boolean type or not.