-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/core#1959 Brick\Math\Exception\RoundingNecessaryException #18206
Conversation
(Standard links)
|
@chamilwijesooriya thanks for this are you able to either rebase this PR against 5.29 branch or create a new PR for the 5.29 branch as it is the RC and this is a recent regression |
So here's a little throw-away script to see whether/how the behavior changes with inputs of varying precision: https://gist.github.com/totten/d6894af0580e61d09cac4357952b5353 I ran this locally on PHP 7.1.33 w/both
The patch changes the outcome when the right-hand side has unusually high precision:
Basically, the change is on this question: "What do you do when subtracting currencies with unusually high precision?"
From a general code-aesthetic POV, I think this change makes the function more consistent/intuitive. But I guess the real question is: "what rounding policy makes sense for the use-case?" Thankfully (at least within core), there only seems to be one caller/use-case: civicrm-core/CRM/Contribute/BAO/Contribution.php Lines 4181 to 4200 in 11af302
The RHS ( (I've got 🤞 for "doesn't really matter".) |
@seamuslee001 thanks for that |
@totten good stuff! I think a decimal point makes a huge difference in cases like bit coins but again it's rare. In the long run you can add precision for each currency and limit front end input accordingly, might solve the issues, as seen in this code civicrm-core/CRM/Utils/Money.php Lines 114 to 128 in c3852f1
But can't really help with irrationals |
Overview
When viewing/editing a contribution, throws Brick\Math\Exception\RoundingNecessaryException: "Rounding is necessary to represent the result of the operation at this scale."
Happens in 5.28.0 as a regression of #17608
Before
Steps to reproduce
After
Contribution can be viewed/edited correctly
Technical Details
The issue happens due to BCMath PHP extension. If GMP is installed, it works as intended. The following code in BrickMath chooses the class accordingly https://github.com/brick/math/blob/63dc40f6a2bbebf670b4d4b5f16bef2458a61402/src/Internal/Calculator.php#L76-L94
Upon further investigation showed that while
$leftOp
amount is taken asBigNumber
while$rightOp
is taken asBigRational
as that amount is not converted in the following codecivicrm-core/CRM/Utils/Money.php
Lines 141 to 144 in c3852f1
Therefore added code to get
Money::of
to$rightOP
as well.Comments
Not sure how rounding might affect this