#31841: DecimalField doesnt't respect max_digits when converting
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
bellini666 |
Type: Bug | Status: new
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
A field defined like this:
{{{
foo = models.DecimalField(max_digits=20, decimal_places=6)
}}}
When trying to set a float 0.2 it would give an error regarding the
maximum decimal places. That because the context that converts the float
to decimal only respect max_digits:
{{{
In [1]: import decimal
In [2]: c = decimal.Context(prec=20)
In [3]: c.create_decimal_from_float(0.2)
Out[3]: Decimal('0.20000000000000001110')
}}}
For floats django should probably round the value to the decimal_places
defined in the field.
--
Ticket URL: <https://code.djangoproject.com/ticket/31841>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.661f50d6b5ee581aa535c8edff284504%40djangoproject.com.