Bug 7528 - amount subtracting 1 cent
Summary: amount subtracting 1 cent
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Acquisitions (show other bugs)
Version: 3.6
Hardware: All All
: P5 - low critical (vote)
Assignee: Henri-Damien LAURENT
QA Contact: Ian Walls
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-10 21:57 UTC by Nicole C. Engard
Modified: 2019-06-27 09:24 UTC (History)
2 users (show)

See Also:
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 (1.13 KB, patch)
2012-04-15 15:23 UTC, Marc Véron
Details | Diff | Splinter Review
Bug 7528 - amount subtracting 1 cent (1.14 KB, patch)
2012-04-16 15:37 UTC, Ian Walls
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.