Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
erp5 erp5
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Labels
    • Labels
  • Merge requests 139
    • Merge requests 139
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • 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
None
Milestone
None
Assign milestone
Time tracking
Source branch: feat/round_half_up
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7