python设置自己的货币

2024-10-05 14:28:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我想设定我自己的货币(优先选择后面的货币)

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

现在我想使用分组,但不是前面的$,而是后面的ISK。 不太清楚该怎么做


Tags: inselfforobjectsdef货币itemsfilter
1条回答
网友
1楼 · 发布于 2024-10-05 14:28:49

你可以试试下面的例子。第一个print语句将以字符串形式给出当前的区域设置值(例如:en_IN for india),第二个语句将提供一个包含区域设置值和iso代码的元组(例如:('en_IN','ISO8859-1'))

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

相关问题 更多 >