[Koha-bugs] [Bug 7528] amount subtracting 1 cent

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Sun Apr 15 17:13:33 CEST 2012


http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=7528

Marc Véron <veron at veron.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |In Discussion
                 CC|                            |veron at veron.ch

--- Comment #1 from Marc Véron <veron at veron.ch> ---
This one has to do with floating point precision in JavaScript.

In
koha-tmpl/intranet-tmpl/prog/en/js/acq.js
function calcNeworderTotal()
we have at line number 667:
var ecost = new Number(Math.floor(rrp * (100 - discount ))/100);

If discount rrp is 35.55 and discount is 0.00, we get a calculation 35.55*100

In JavaScript, this evaluates to 3554.9999999999995

which then is rounded down to the next deeper integer (floor) = 3554, divided
by 100 = 35.54

Same can happen with other values.

As a quick workaround I replaced the line with:

var ecost = rrp;
if (100-discount != 100) { //Prevent rounding issues if no discount
    ecost = new Number(Math.floor(rrp * (100 - discount ))/100);
}

Now, the field gets always the correct value if there is no discount.

Note: With some discount there still could be some tiny rounding errors by 1
cent.

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list