https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43956
Bug ID: 43956
Summary: Koha::Number::Price::round returns wrong or
inconsistent results
Initiative type: ---
Sponsorship ---
status:
Product: Koha
Version: Main
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P5 - low
Component: Architecture, internals, and plumbing
Assignee: [email protected]
Reporter: [email protected]
QA Contact: [email protected]
Blocks: 23728
Target Milestone: ---
Koha::Number::Price::round returns wrong or inconsistent results, and its
rounding disagrees with Koha::Number::Price::format. This is part of the
currency rounding work collected on bug 23728 and is the foundation for the
rest of it.
Observed on main (round / format / sprintf %.2f):
0.825 round=0.82 format=0.83 sprintf=0.82
-0.825 round=-0.82 format=-0.83 sprintf=-0.82
1.005 round=1 format=1.01 sprintf=1.00
0.285 round=0.28 format=0.29 sprintf=0.28
0.125 round=0.12 format=0.13 sprintf=0.12
0.005 round=00 format=0.01 sprintf=0.01
0.004 round=00 format=0.00 sprintf=0.00
"abc" round=NaN format=0.00
"1,5" round=NaN format=1.00
Causes:
- round uses Math::BigFloat with its default half-even mode, while format uses
Number::Format on binary floats, so the two disagree.
- round returns the string from bdstr, which can be "00" and "NaN".
- Input is not validated.
Proposed:
- Use one decimal-arithmetic implementation (Math::BigFloat) for round and
format.
- Return numeric values from round, never "00" or "NaN"; throw on non-numeric
input.
- Add a rounding mode parameter: half_away_from_zero (default), half_up,
half_down, half_even (banker's), half_odd.
- Keep decimal digits a parameter (default 2) so bug "currency decimal_digits"
can supply it later.
- Check existing callers (C4::Overdues, Koha::Acquisition::Order,
C4::Acquisition::get_rounded_price) for reliance on the old behaviour.
Tests: table-driven for every mode, including negatives and exact halves.
Referenced Bugs:
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23728
[Bug 23728] Rounding code should be moved to a Koha module so code can be
centralised
--
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/