-1

I am trying to retrieve a balance of an account that is stored in an excel worksheet and display that to a tkinter gui. I get the number to display but I need it formatted with the $ and 2 decimal points. Any help would be much appreciated. Code:

# Import Modules as needed
from openpyxl import Workbook, load_workbook
from openpyxl.styles import numbers

# Load spreadsheet file
wb = load_workbook(filename = 'money.xlsx')

# Load all needed worksheets inside the spreadsheet
ws01 = wb['wc_ck_bal']
ws03 = wb['wc_sv_bal']

# Load Balances from spreadsheet
wc_ck_bal01 = ws01['A1'].value
wc_sv_bal01 = ws03['A1'].value

print(wc_ck_bal01)
print(wc_sv_bal01)

When running said program I get: [screenshot of results]

1

The balances are correct but how do I get them to alway display as currency with the $ and 2 decimal points?

eshirvana
  • 23,227
  • 3
  • 22
  • 38
  • 1
    Please research before posting in accordance with [ask]. Duplicate of [Currency formatting in Python](https://stackoverflow.com/questions/320929/currency-formatting-in-python) – esqew Dec 21 '21 at 03:08

1 Answers1

0

use string format :

print('${number:.2f}'.format(number=wc_ck_bal01))
eshirvana
  • 23,227
  • 3
  • 22
  • 38