What is the difference between print("%.2f" % total) and print total?


#1


What is the meaning of this code ?
print("%.2f" % total)

I could have wrote
print total
So what is the difference between print("%.2f" % total) and print total


print("%.2f" % total)


#2

print total will output raw values with any number of decimal places.

will print a number with only two decimal places.

The f stands for float which is what we call a number with a decimal fraction, even if it is zero.

0    => integer
0.0  => float

#3

Thank you so much :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.