#26459: DecimalField float rounding
----------------------------------------------+--------------------
     Reporter:  yasondinalt                   |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.9
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  1
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 DecimalField has weird behavior in case of float values passed to field.
 If decimal_places = 1
 float 2.15 will be saved as 2.1 (!)
 float 2.25 will be saved as 2.2 (!)
 But if float value first converted to str:
 float 2.15 will be saved as 0.2 (ok)
 float 2.25 will be saved as 0.2 (!)
 It's because of default decimal rounding ROUND_HALF_EVEN.
 As I understand build-in round() use rounding similar to ROUND_HALF_UP.

 I tried first cast float to str, then use ROUND_HALF_UP, so now:
 float 2.15 will be saved as 0.2 (ok)
 float 2.25 will be saved as 0.3 (ok)

--
Ticket URL: <https://code.djangoproject.com/ticket/26459>
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/054.f981668fae30064528b2caa9bda9a918%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to