【发布时间】:2021-04-28 20:22:25
【问题描述】:
所以我刚开始使用 Django 并使用它来存储表示为 1.21242、1.20641 等的外汇价格...
model.py
from django.db import models
# Create your models here.
class ForexPrice(models.Model):
openPrice = models.DecimalField(max_digits=6, decimal_places=6)
highPrice = models.DecimalField(max_digits=6, decimal_places=6)
lowPrice = models.DecimalField(max_digits=6, decimal_places=6)
closePrice = models.DecimalField(max_digits=6, decimal_places=6)
我的问题是:
max_decimal 和 decimal_places 属性如何工作?我在这两个字段中都使用了 6,假设 max_digits=6 将允许值最多存储 6 位数字,即:123456.000000 而decimal_palces=6 将支持高达 000000.123456 的值。
这个假设是正确的还是我遗漏了什么?
将记录保存到数据库时出现以下错误:
精度为 6、标度为 6 的字段必须舍入为小于绝对值 大于 1。
【问题讨论】:
-
@iklinac 感谢分享资源。是的,我看到了他们的文档,但是他们提供的示例对我来说没有意义,直到我在下面看到 KKAs 的回答。
标签: python django django-models