| Summary: | amount subtracting 1 cent | ||
|---|---|---|---|
| Product: | Koha | Reporter: | Nicole C. Engard <nengard> |
| Component: | Acquisitions | Assignee: | 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 | ||
| GIT URL: | Initiative type: | --- | |
| Sponsorship status: | --- | Crowdfunding goal: | 0 |
| Patch complexity: | --- | Documentation contact: | |
| Documentation submission: | Text to go in the release notes: | ||
| Version(s) released in: | Circulation function: | ||
| Attachments: |
Bug 7528 - amount subtracting 1 cent
Bug 7528 - amount subtracting 1 cent |
||
|
Description
Nicole C. Engard
2012-02-10 21:57:20 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.
Created attachment 9207 [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 Javascript only change to prevent discount calculation if there is no discount to calculate. Marking as Signed Off and Passed QA in one go. 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> There have been no further reports of problems so I am marking this bug resolved. |