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
#11
(Sep-01-2017, 02:31 PM)hbknjr Wrote:
(Aug-30-2017, 08:59 AM)Crackity Wrote: I was wondering though if there is a certain situation[s] where one option is preferred over the other?
"{}".format(arg) is for formatting string and printing them. You'll receive a string when using it

whereas round(number,ndigits) is used to round off, it returns float which can further be used for calculations.

Ahh, that explains it! I almost posted it here but thought better of it, but after I finished the tip calculator and moved on to the next project I attempted to make use of both examples to verify that it worked the way I thought it would... and it didn't!

However your explanation... explains it! Smile

On my next project I was supposed to have some user input and some set data, (non iterable??? Blush ) then combine them and provide a grand total. I noticed that when I used the "round" option it printed $1000.0 instead of $1000.00. I went back and just used the "format" option instead, which seemed to fix it, but now realize that I had them reversed... Or did I?

Sorry just went back and double checked and thought I understood, but now am confused again. If I enter for example:

prep = 1000.00

does Python see that as a string or is it automatically defined as an integer or floating point due to the " . "?

If it still sees it as a string then mystery solved, but if it's already an integer by default then I don't know why the "round" option didn't work for me.

Either way I started this response to say thank you for all of your assistance!

And to Dead_EyE? Vielen Dank for deine hilfe mein freunde.
before you get excited, Ich spreche nur ein bissien Deutche. Big Grin
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 - Sep-04-2017, 07:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Histogram using pandas dataframe not showing proper output ift38375 1 2,228 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