Python sets its own currency with the language version

I would like to set my own currency (preferably behind it first)

def total_price(self):
    items = SellItem.objects.filter(selllist=self)
    total = 0
    for item in items:
        total += item.amount * item.price

    locale.setlocale(locale.LC_ALL, '')
    total = locale.currency(total, grouping=True)
    return total

Now I would like to use grouping, but instead of $ up front, I would like to have ISK behind. Not quite sure how to do this.

+4
source share
1 answer

You can try the example below. the first print request will provide the current locale value as a string (Ex: en_IN for india), and the second will give you a tuple that has both the locale value and the iso code (Ex: ('en_IN', 'ISO8859-1') )

import locale
print locale.setlocale(locale.LC_ALL, '')
print locale.getlocale()
0
source

Source: https://habr.com/ru/post/1523628/


All Articles