Paritosh Singh
Paritosh Singh

Reputation: 6404

How to convert number to comma separated string in Django

I want to convert price to standard comma separated string for a given country. For example if we do it for India 100000 should convert to 10,00,000, but for US it should convert to 1,000,000.

I have seen locale library in python. It can be done using that.

E.g:

>> import locale
>> locale.setlocale(locale.LC_ALL, 'en_US.utf8')
>> locale.format("%.2f", 100028282.23, grouping=True)

It works.

But i just want to know whether can we do it in Django using localization.

Upvotes: 2

Views: 546

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31971

Yes, localization can do that. Also take a look at THOUSAND_SEPARATOR, NUMBER_GROUPING, DECIMAL_SEPARATOR and USE_THOUSAND_SEPARATOR settings.

Upvotes: 4

Related Questions