Bug 7528

Summary: amount subtracting 1 cent
Product: Koha Reporter: Nicole C. Engard <nengard>
Component: AcquisitionsAssignee: Henri-Damien LAURENT <henridamien>
Status: CLOSED FIXED QA Contact: Ian Walls <koha.sekjal>
Severity: critical    
Priority: P5 - low CC: paul.poulain, veron
Version: 3.6   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Attachments: Bug 7528 - amount subtracting 1 cent
Bug 7528 - amount subtracting 1 cent

Description Nicole C. Engard 2012-02-10 21:57:20 UTC
When adding an order if you enter an amount and hit tab it puts the amount minus 1 cent in the next couple fields - see here: http://screencast.com/t/SbVVtte8zHvk 

It's crazy - and critical that it be fixed.

Nicole
Comment 1 Marc Véron 2012-04-15 15:13:33 UTC
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.
Comment 2 Marc Véron 2012-04-15 15:23:58 UTC Comment hidden (obsolete)
Comment 3 Ian Walls 2012-04-16 15:36:34 UTC
Javascript only change to prevent discount calculation if there is no discount to calculate.  Marking as Signed Off and Passed QA in one go.
Comment 4 Ian Walls 2012-04-16 15:37:39 UTC
Created attachment 9218 [details] [review]
Bug 7528 - amount subtracting 1 cent

Rounding issue with JavaScript and float numbers, JavaScript changed to do no calculation if discount is 0

Signed-off-by: Ian Walls <koha.sekjal@gmail.com>
Comment 5 Jared Camins-Esakov 2012-12-31 00:56:43 UTC
There have been no further reports of problems so I am marking this bug resolved.