If you are using OSX and have yet to set your locale module setting this first answer will not work you will receive the following error:
Traceback (most recent call last):File "<stdin>", line 1, in <module> File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/locale.py", line 221, in currency
raise ValueError("Currency formatting is not possible using "ValueError: Currency formatting is not possible using the 'C' locale.
To remedy this you will have to do use the following:
#printing the variable 'Total:' in a format that looks like this '9,348.237'
print ('Total:', '{:7,.3f}'.format(zum1))
where the '{:7,.3f}' es the number of spaces for formatting the number in this case is a million with 3 decimal points.
Then you add the '.format(zum1). The zum1 is tha variable that has the big number for the sum of all number in my particular program. Variable can be anything that you decide to use.
Not quite sure why it's not mentioned more online (or on this thread), but the Babel package (and Django utilities) from the Edgewall guys is awesome for currency formatting (and lots of other i18n tasks). It's nice because it doesn't suffer from the need to do everything globally like the core Python locale module.
If you are using OSX and have yet to set your locale module setting this first answer will not work you will receive the following error:
To remedy this you will have to do use the following:
#printing the variable 'Total:' in a format that looks like this '9,348.237'
where the '{:7,.3f}' es the number of spaces for formatting the number in this case is a million with 3 decimal points. Then you add the '.format(zum1). The zum1 is tha variable that has the big number for the sum of all number in my particular program. Variable can be anything that you decide to use.
A lambda for calculating it inside a function, with help from @Nate's answer
and then,
Not quite sure why it's not mentioned more online (or on this thread), but the Babel package (and Django utilities) from the Edgewall guys is awesome for currency formatting (and lots of other i18n tasks). It's nice because it doesn't suffer from the need to do everything globally like the core Python locale module.
The example the OP gave would simply be:
I've come to look at the same thing and found python-money not really used it yet but maybe a mix of the two would be good
See the locale module.
This does currency (and date) formatting.