Python Forum

Full Version: Formatting Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
code

sales_tax = food_charge*.08
print('The sales tax is: $', sales_tax)
Output:
The sales tax is: $ 0.8
looking at how to format to get that to be 0.80
Also if I can to get the 0.80 to be right beside the $ sign
There is Format Specification Mini-Language.

If using 3.6 <= Python then f-strings are way to go:

>>> food_charge = 11.99
>>> sales_tax = food_charge * 0.08
>>> print(f'The sales tax is ${sales_tax:.2f}')
The sales tax is $0.96
(Jun-02-2019, 09:13 PM)perfringo Wrote: [ -> ]There is Format Specification Mini-Language.

If using 3.6 < Python then f-strings are way to go:

>>> food_charge = 11.99
>>> sales_tax = food_charge * 0.08
>>> print(f'The sales tax is ${sales_tax:.2f}')
The sales tax is $0.96

ur amazing, and it was in my notes the entire time and I completely looked over or did something weird with it. thank you!