Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • erp5 erp5
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Merge requests 141
    • Merge requests 141
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Jobs
  • Commits
Collapse sidebar
  • nexedi
  • erp5erp5
  • Merge requests
  • !1876

Closed
Created Feb 15, 2024 by Kazuhiko Shiozaki@kazuhikoOwner
  • Report abuse
Report abuse

Feat/round half up

  • Overview 22
  • Commits 257
  • Changes 583

Override built-in round() so that it always behave as ROUND_HALF_UP.

In python 2

for i in (-1.5, -0.5, 0.5, 1.5):
  print i, round_orig(i), round(i)
-1.5, -2.0, -2.0
-0.5, -1.0, -1.0
0.5, 1.0, 1.0
1.5, 2.0, 2.0

for i in (-.15, -.05, .05, .15):
  print i, round_orig(i,1), round(i,1)
-0.15, -0.1, -0.2
-0.05, -0.1, -0.1
0.05, 0.1, 0.1
0.15, 0.1, 0.2

In python 3

for i in (-1.5, -0.5, 0.5, 1.5):
  print(i, round_orig(i), round(i))
-1.5 -2 -2.0
-0.5 0 -1.0
0.5 0 1.0
1.5 2 2.0

for i in (-.15, -.05, .05, .15):
  print(i, round_orig(i,1), round(i,1))
-0.15 -0.1 -0.2
-0.05 -0.1 -0.1
0.05 0.1 0.1
0.15 0.1 0.2

This behaviour is different than MySQL/MariaDB implementation for approximate-value numbers (like float/double).

mysql> SELECT ROUND(2.5), ROUND(CAST(2.5 AS DOUBLE));
+------------+----------------------------+
| ROUND(2.5) | ROUND(CAST(2.5 AS DOUBLE)) |
+------------+----------------------------+
|          3 |                          2 |
+------------+----------------------------+

You can see MariaDB implementation that uses libc's rint(), not round().

Edited Feb 15, 2024 by Kazuhiko Shiozaki
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: feat/round_half_up
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7