Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

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

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.