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
#16
(Sep-04-2017, 10:48 AM)DeaD_EyE Wrote:
Quote:If you just want to output a string for dollar, i18n is overkill.
In this case the normal formatting method is the easiest way to solve the problem quickly.

fmt = '$ {:.2f}'
value = 1.1337
final_string = fmt.format(value)
print(final_string)

# or shorter
print('$ {:.2f}'.format(value))

# since python 3.6 with format strings
print(f'{value:.2f}')
The curly braces are replaced by the variable. The text after the colon is the format specifier.
Here you get a good overview: https://pyformat.info/

Schöne Grüße aus Deutschland :-)
Maybe i flight this year back to Zibo to my girlfriend :-)

Thanks so much for your detailed explanation! Best wishes!
Reply


Messages In This Thread
RE: tip calculator not displaying proper dollar format - by syogun - Sep-04-2017, 11:15 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