I want to format price in integer to properly formatted currency. Example 10000 to or ₹10,000
So, I am using the following commands in python
import locale
locale.setlocale(locale.LC_MONETARY, 'en_US')
or
locale.setlocale(locale.LC_MONETARY, 'en_IN')
print str(locale.currency(10000, grouping=True))
When I use the above commands in python in ubuntu in different laptop, they are working perfectly fine. But, on windows they are not working.
Its giving me error as follows
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\locale.py", line 581, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
How to solve this error ?
I am using Windows 10. I open cmd and type "python" enter. The python shell is presented with following version. There I type the above commands.
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Note :- I tried copying the locale.py file from python directory in ubuntu system to Windows directory i.e., "C:\Python27\Lib" but its still not working.
You can take a look at the pycountry library to have a mapping between Windows and Linux language codes:
Then you can do:
EDIT
To format currency values, you may consider using Babel, for instance: