Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
139
Merge Requests
139
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
c4f64983
Commit
c4f64983
authored
Feb 15, 2024
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Type: override round() as ROUND_HALF_UP behaviour.
parent
155c7de5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletion
+37
-1
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+37
-1
No files found.
product/ERP5Type/Utils.py
View file @
c4f64983
...
...
@@ -117,9 +117,41 @@ from zLOG import LOG, BLATHER, PROBLEM, WARNING, INFO, TRACE
from
Products.ERP5Type.Globals
import
get_request
#####################################################
#
Compatibility - XXX - BAD
#
ROUND_HALF_UP round()
#####################################################
from
ctypes
import
cdll
,
c_float
from
decimal
import
localcontext
,
Decimal
,
ROUND_HALF_UP
round_orig
=
__builtins__
[
'round'
]
libm
=
cdll
.
LoadLibrary
(
'libm.so.6'
)
libm
.
roundf
.
restype
=
c_float
def
round
(
number
,
ndigits
=
None
):
if
ndigits
is
not
None
and
not
isinstance
(
ndigits
,
int
):
raise
TypeError
(
'optional arg must be an integer'
)
if
ndigits
:
if
isinstance
(
number
,
Decimal
):
scale
=
Decimal
(
10
)
**
ndigits
else
:
scale
=
10
**
ndigits
else
:
scale
=
1
number
*=
scale
if
isinstance
(
number
,
(
int
,
Decimal
)):
with
localcontext
()
as
round_context
:
round_context
.
rounding
=
ROUND_HALF_UP
if
isinstance
(
number
,
int
):
result
=
int
(
round_orig
(
Decimal
(
number
),
0
))
else
:
result
=
round_orig
(
number
,
0
)
else
:
result
=
libm
.
roundf
(
c_float
(
number
))
result
/=
scale
return
result
__builtins__
[
'round'
]
=
round
from
.Accessor.TypeDefinition
import
type_definition
from
.Accessor.TypeDefinition
import
list_types
...
...
@@ -139,6 +171,10 @@ else:
import
__builtin__
cmp
=
__builtin__
.
cmp
#####################################################
# Compatibility - XXX - BAD
#####################################################
#####################################################
# Generic sort method
#####################################################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment