See the locale module.
This does currency (and date) formatting.
>>> import locale
>>> locale.setlocale( locale.LC_ALL, '' )
'English_United States.1252'
>>> locale.currency( 188518982.18 )
'$188518982.18'
>>> locale.currency( 188518982.18, grouping=True )
'$188,518,982.18'
Answer from S.Lott on Stack OverflowMonepy
A python package that implements currency classes to work with monetary values.
Target audience
I created it mostly for some data analysis tasks I usually do, and also as way to learn about project structure, documentation, github actions and how to publish packages.
I wouldn't know if it's production ready.
Comparison
After starting it I found about py-moneyed. They are quite similar, but I wanted something that looks "cleaner" when using it.
Any feedback will be appreciated.
Videos
» pip install currencies
» pip install CurrencyConverter
See the locale module.
This does currency (and date) formatting.
>>> import locale
>>> locale.setlocale( locale.LC_ALL, '' )
'English_United States.1252'
>>> locale.currency( 188518982.18 )
'$188518982.18'
>>> locale.currency( 188518982.18, grouping=True )
'$188,518,982.18'
New in 2.7
>>> '{:20,.2f}'.format(18446744073709551616.0)
'18,446,744,073,709,551,616.00'
http://docs.python.org/dev/whatsnew/2.7.html#pep-0378
So i have been webscraping a lot in the last two weeks and i come across currencies, some have whole value while others are decimals.
Now how can i convert them to decimal with two digits after the decimal point ?
example:
$10
$11.56
$12.99
Output i Want:
10.00
11.56
12.99
i have tried round(float(10.00),2) after of course removing the $ sign with replace..
but i end up with 10.0, 11.5 and 12.9
Please Help :)