Write a Python program to print the following floating numbers upto 2 decimal places


The program is written in Python and is used to format floating point values. The program takes two floating point numbers as input (a and b) and then formats them to show only two decimal places. The first line defines the variable "a" and assigns it a value of 84.4423. The second line defines the variable "b" and assigns it a value of 23.36778.

Next, the original values of a and b are printed using the "print" statement. After that, the formatted values of a and b are printed using the "format" function. The "{:.2f}".format(a) and "{:.2f}".format(b) statements are used to format the values of a and b to show only two decimal places. The ".2f" format specifier is used to format the values to 2 decimal places. The "f" stands for "floating point". Finally, an empty line is printed to separate the outputs of the two variables.

Source Code

a = 84.4423
b = 23.36778
print("Original Value A : ", a)
print("Formatted Value A : "+"{:.2f}".format(a));
print("Original Value B : ", b)
print("Formatted Value B : "+"{:.2f}".format(b));
print() 

Output

Original Value A :  84.4423
Formatted Value A : 84.44
Original Value B :  23.36778
Formatted Value B : 23.37


Example Programs