dev/core/#299 Fix mishandling of non decimal currency on additional payment form. #12626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Fixes mis-loading of default for amount on record payment form when non decimal thousand separators used
Before
Currency loads with a decimal point even when a comma decimal separator is configured
After
Currency loads with a comma when a comma decimal separator is configured
Technical Details
I tried to use as much of @mattwire work as relevant to solve this
https://github.com/civicrm/civicrm-core/pull/12055/files
What I found in there was that the code assumed that the code extracted to formatNumericByFormat fixed thousand separators but it in fact didn't. What I found is it converted '70' to '70.00' but in fact it didn't & required the self::replaceCurrencySeparators($amount); sequence to do that work. As a result I made formatNumeric protected & exposed 2 wrappers
@mattwire what do you think - this brings across some but not all of your work in a specific context - which could go broader. My big concern with the existing money format function is that it tries to do something for everyone & handle too many things.
We could shorten the function names - ie.
formatLocaleNumericByCurrency
formatLocaleNumericRoundedDefaultCurrency
Although if we later thought 'we only sometimes want to round' we'd find someone adding a magic param & we would start rebuilding 'format'
We could actually solve this bug with the existing format function except we would lose the rounding that is in the current function.
Comments