MoneyDjango:如何从原始货币中获得价值?

2024-06-01 06:41:23 发布

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

我用这个包来装饰我的货币领域: https://github.com/django-money/django-money

我有一个模态场:

client_cost = MoneyField(
        _('client cost'),
        max_digits=10,
        decimal_places=2,
        default_currency='AUD',
        null=True,
    )

现在我想对它进行一些计算,所以我使用int(client_cost)将其转换为int 但是我得到了一个错误(很明显):

^{pr2}$

请帮忙。在


Tags: djangohttpsgithubcomclient货币装饰max
1条回答
网友
1楼 · 发布于 2024-06-01 06:41:23

您正在处理一个Money对象(see here)。该对象具有一个amount属性,该属性将给出十进制数:

>>> client_cost.amount
Decimal('19.50')

如果愿意,可以将其转换为int。在

相关问题 更多 >