#29844: djang orm cast DecimalField to FloatField forced rounding
-------------------------------------+-------------------------------------
Reporter: Ron | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When I cast a DecimalField to Float, the float value gets rounded which
creates wrong results.
For example is `decimalfield`=75.75 and in the annotation I see 76 in
`decimalfield_float`. Seen in django 1.11.15 on MariaDB.
Model:
{{{
class MyModel(models.Model):
floatfield = models.FloatField('My FloatField')
decimalfield = models.DecimalField(_("My DecimalField"),
decimal_places=2, max_digits=12,
validators=[MinValueValidator(Decimal('0.01'))])
}}}
Query:
{{{
MyModel.objects.all().annotate(decimalfield_float=Cast('decimalfield',
FloatField()))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29844>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.14ecae2c79cd7a2b90f682a80b06df5e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.