Explanation of print("%.2f" % total)


the code is like that :smiley:

meal = 44.50
tax = 0.0675
tip = 0.15

meal = meal + meal * tax
total = meal + meal * tip

print("%.2f" % total)
why we added "%.2f" % to the total?


In the future, make sure to mark your code as preformatted text.

Formatting specification is described here:
look for mentions of '.' and 'f' if you just want that specific case described.


I've read the link you specified here still unable to understand this "%.2f"


The % is some kind of placeholder and the f stands for "float"
What the %.2f does, is to fill this place with total, but only 2 numbers after the comma (for example: 22,45).
At the end line, the % total tells the editor, that the placeholder will be filled with total.

So print("%.2f") % total will print the total with 2 numbers after the comma.


Special characters always throw me off.

Thanks frozen!


You're welcome, happy to help anytime :smiley: