#32555: DecimalField Rounding inconsistency (PostgreSQL)
-------------------------------------+-------------------------------------
Reporter: bluppfisk | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: decimalfield, | Triage Stage:
rounding, float | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by bluppfisk):
I agree that is related, but even as I imitate Django's behaviour by using
its own field and field configuration, the rounding is correct. It is only
when I leave it fully up to Django that the rounding error happens.
{{{
def _normalize_positions(self):
decimal_field = self._meta.get_field('positions').base_field
self.positions = [
decimal_field.context.create_decimal_from_float(val)
.quantize(Decimal("1").scaleb(-decimal_field.decimal_places),
context=decimal_field.context)
for val in self.positions
]
}}}
> [Decimal('6586.878'), Decimal('0.204'), Decimal('0.715')]
This is good.
What is Django doing differently than me? It would seem logical that
Django takes care of the normalising in a reproducible way.
--
Ticket URL: <https://code.djangoproject.com/ticket/32555#comment:2>
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/067.66fd6729daccbfef7734402899f28870%40djangoproject.com.