Python Forum
tip calculator not displaying proper dollar format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tip calculator not displaying proper dollar format
#5
(Aug-30-2017, 08:36 AM)hbknjr Wrote: Use:
print('To tip 20% the amount is: $ {:.2f}'.format(tip20))
Another way is to use [url=https://docs.python.org/3/library/functions.html#round]round[/url].

print('To tip 20% the amount is: $',round(tip20,2))

This was the answer I was looking for!! Thank you so much!!
I used both of your suggestions and they both solved the issue at hand. I was wondering though if there is a certain situation[s] where one option is preferred over the other?

I just wanted to post this to show anyone else that might have this same problem arise.

Here is the code with the new changes, I incorporated both to demonstrate that they both give the same desired result.

Thanks again to HBKNJR, and others for your help!! Smile

food = float(input('What is your food total?: '))

tax = 0.08 * food 
print('The sales tax is: $ {:.2f}'.format(tax))

total = tax + food
print('\nYour total bill comes to: $ {:.2f}'.format(total))


tip10 = 0.10 * total
tip15 = 0.15 * total
tip20 = 0.20 * total
print('\nTo tip 10% the amount is: $ {:.2f}'.format(tip10))
print('To tip 15% the amount is: $',round(tip15,2))
print('To tip 20% the amount is: $',round(tip20,2))
And the new and improved output:

Output:
What is your food total?: 56.85 The sales tax is: $ 4.55 Your total bill comes to: $ 61.40 To tip 10% the amount is: $ 6.14 To tip 15% the amount is: $ 9.21 To tip 20% the amount is: $ 12.28 >>>
Quote:If you can't learn to do something well?... Learn to enjoy doing it poorly.
Reply


Messages In This Thread
RE: tip calculator not displaying proper dollar format - by Crackity - Aug-30-2017, 08:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Histogram using pandas dataframe not showing proper output ift38375 1 2,270 Jul-04-2019, 10:43 PM
Last Post: scidam

Forum Jump:

User Panel Messages

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