[Django]-Is there a way to extract just the decimal value from django-money MoneyField without currency value?

4👍

Django’s MoneyField uses the Money class of the py-moneyed package [GitHub] as the “Python side” of the data.

This Money class [GitHub] has basically two attributes: amount, and currency.

So if you have Money object, you can retrieve the .amount object, as is demonstrated on the GitHub page:

>>> from moneyed import Money, USD
>>> price = Money('19.50', USD)
>>> price
19 USD

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

>>> price.currency
USD

>>> price.currency.code
'USD'

You can thus create Money objects by calling the constructor, and retrieve the attributes to do indivual process of the amount and the currency.

Leave a comment