Python Decimal places

Python program to get a fractional number from user and display the same in two digit precision

Sample Input 1:

56.3426

Sample Output 1:

56.34

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

				
			
					
num=float(input("Enter a Number:"))
print("{:.2f}".format(num))

			
				
			

Program Explanation

In python format specifiers are mentioned inside {} and value for the specifiers are passed through the format() method.

Here :.2f specifies float value with 2 decimal point.

Comments