openerp-india team mailing list archive
-
openerp-india team
-
Mailing list archive
-
Message #01456
[Bug 882036] Re: rounding error
Well, Python's round() seems to be an asymmetrical half up algorithm, as
opposed to the symmetrical half up rounding in common math. Using
epsilon will not correct that. I grand you the sign issue, but not the
precision issue you mentioned.
Corrected algorithm:
def roundf(f, prec=0):
return round(f + cmp(f, 0.0) * (.1 / pow(10, prec + 2), prec)
>>> roundf(-2.675000000000005, 14)
-2.67500000000001
>>> roundf(2.675000000000005, 14)
2.67500000000001
>>> roundf(2.675000000000005, 15)
2.675000000000005
>>> roundf((-2.675000000000005, 15)
-2.675000000000005
>>> roundf(0.575,2)
0.58
>>> roundf(2.675,2)
2.68
>>> roundf(-2.678,2)
-2.68
Cheers
--
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/882036
Title:
rounding error
Status in OpenERP Server:
New
Bug description:
Concerns 6.0 and trunk.
If you define a precision of 0.01, the rounding of 0.125 must be 0.13 and not 0.12. The error is in the call of the format string "%.2f"%val which introduces a mathematical error. The round function must be called to apply the correct rounding before formatting the string. It should be:
"%.2f"%round(val*100)/100
Fix class digits_change of class float in the server. BUT fix also the gtk client AND web client as they all have that error (I let you find the right line)
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/882036/+subscriptions
References