Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting Help
#1
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
Reply
#2
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020