Answers:
field = models.DecimalField(max_digits=8, decimal_places=2)请注意,max_digits应为> =小数位数。此示例设置将允许的值最大为:999,999.99
文件:https://docs.djangoproject.com/en/1.10/ref/models/fields/#decimalfield
其他答案是100%正确的,但不是很实用,因为您仍然必须手动管理输出,格式等。
我建议使用django-money:
from djmoney.models.fields import MoneyField
from django.db import models
def SomeModel(models.Model):
    some_currency = MoneyField(
        decimal_places=2,
        default=0,
        default_currency='USD',
        max_digits=11,
    )从模板自动工作:
{{ somemodel.some_currency }}输出:
$123.00它通过python-money具有强大的后端功能,本质上是标准十进制字段的替代品。
DecimalField更为实用。而且我相信它适用于大多数人。django-money如突出显示的那样使用,包括货币处理。因此,这是更涉及交易,如电子商务网站,支付网关,数字货币,银行,等....项目
                    定义一个小数,并在该值前面返回$符号。
    price = models.DecimalField(max_digits=8, decimal_places=2)
    @property
    def price_display(self):
        return "$%s" % self.pricefield = models.DecimalField(max_digits=8, decimal_places=2)应该为PostgreSQL创建一个字段,例如:
 "field" numeric(8, 2) NOT NULL这是PostGreSQL存储美元金额的最佳方法。
如果需要PostgreSQL字段类型“双精度”,则需要在Django模型中执行:
field = models.FloatField()