pythondjangodjango-modelsdjango-model-field

What is the best django model field to use to represent a US dollar amount?


I need to store a U.S. $ dollar amount in a field of a Django model. What is the best model field type to use? I need to be able to have the user enter this value (with error checking, only want a number accurate to cents), format it for output to users in different places, and use it to calculate other numbers.


Solution

  • A decimal field is the right choice for the currency value.

    It will look something like:

    credit = models.DecimalField(max_digits=6, decimal_places=2)