[Koha-bugs] [Bug 21507] Decimal separators issues in patrons payments/fines, simplified

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Apr 22 17:07:06 CEST 2021


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=21507

--- Comment #10 from Martin Renvoize <martin.renvoize at ptfs-europe.com> ---
I'm coming back around to thinking about this as a coercion/validation
function.

We need to allow for pasted input.. so that could include any of the following
forms.


$ 1,000
$1000
$1000.00
$1,000.00
1,000.00$
1000.00$
1000$
USD 1000

etc, etc.. the list goes on with various symbols and strings denoting currency
and various delimiters and lack of delimiters.

I think perhaps we need to parse all input number during the validation step
and coerce them into a standard form prior to form submissions.

Generally speaking I think the following could/shoould catch all cases.

1. Drop non-digit character (excluding delimiters [comma and dot])
2. Work backwards to find if we have decimal digits (i.e. 2 digits after either
a comma or dot)
3. If we find a decimal delimiter, drop the opposit delimiter from the string
(i.e. if we find a dot then drop any comma's.. if we find a comma, drop any
dots)
4. If we found not decimal delimiter.. check for thousands separator then add
the opposite decimal delimiter and two 0 digits.
5. Repeat step 3.
6. If the decimal separator at this point is a comma, change it to dot upon
submission.

I think that flow would ensure we always end up with a standardised decimal
number with a dot as the decimal separator.. which is what the serverside
controllers all expect I believe.

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


More information about the Koha-bugs mailing list