Display float number with 2 decimal places using print()
Display float number with 2 decimal places using print()
Display float number with 2 decimal places using print()
num = 458.541315
458.54
Use the %.2f formatting code in print() function to format float number to two decimal places.
num = 458.541315
print('%.2f' % num)
58.54
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.