Skip to content

Update float rounding to be closer to python3

Jérome Perrin requested to merge feat/round_half_up_tmp_up into master

Based on these discussions from https://lab.nexedi.com/nexedi/erp5/-/merge_requests/1881 and https://lab.nexedi.com/nexedi/erp5/-/merge_requests/1751, we realized that:

  • with ERP5 on python2, the rounding rules were already not consistent. This new test is failing on python2 current master, the accounting lines are created with round (that is ROUND_HALF_UP), the price in the xhtml_style UI and in the print invoice are rounded with '%0.2f' % f which is ROUND_HALF_EVEN and reports using mariadb with floats are rounded using ROUND_HALF_EVEN, so we already had inconsistencies and I think we only had one case recently of customer complaining about it. I thought changing round would have a major impact, now I start to believe it would probably not even be noticed, or be noticed as fixing a bug.
  • most of the round implementations ( python3's round, python2 '%0.2f' % f, mariadb ) are ROUND_HALF_UP, so it feels better to abandon python2 idea of ROUND_HALF_UP and just use ROUND_HALF_EVEN like everywhere else. That said, javascript is also different here and FloatField on ERP5JS rounds differently from the same FloatField in xhtml_style. We considered "fixing" ERP5JS to also make FloatFields round with ROUND_HALF_EVEN, but we did not do it in this branch, it's a totally independent problem and anyway when using json to transmit floats in javascript they get different binary representation and round differently.
Edited by Jérome Perrin

Merge request reports