-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Form] Fix precision of MoneyToLocalizedStringTransformer's divisions on transform() #26781
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
Conversation
5dff4ee to
5653b4e
Compare
05c0aba to
65e0b29
Compare
65e0b29 to
bddc80d
Compare
| } elseif (isset(self::$customRoundingList[$roundingModeAttribute])) { | ||
| $roundingCoef = pow(10, $precision); | ||
| $value *= $roundingCoef; | ||
| $value = (float) (string) $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why first casting to string and then to float again ? The *= operator means that this is probably not a string already. What happens if you remove this ?
| // array(1.125, '1.13'), | ||
| array(1.127, '1.13'), | ||
| array(1.129, '1.13'), | ||
| array(1020 / 100, '10.20'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not 10.2 rather than a division ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about that example? https://3v4l.org/5ZV3F does not confirm your observation. Should we use another example instead that allows to actually catch potential future regressions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xabbuh yes, you forgot to add floor().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, thanks
|
Don't we have the same issue in 2.7? |
|
I think so. #24036 was merged into |
...omponent/Form/Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php
Outdated
Show resolved
Hide resolved
bddc80d to
b97a4ae
Compare
b25e32b to
f94b7aa
Compare
|
done |
|
Thank you @syastrebov. |
…s divisions on transform() (syastrebov) This PR was merged into the 2.7 branch. Discussion ---------- [Form] Fix precision of MoneyToLocalizedStringTransformer's divisions on transform() | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | no | License | MIT | Doc PR | Related issue #21026. Previous PR #24036. Similar fix for `transform()` method. Commits ------- f94b7aa fix rounding from string
Related issue #21026.
Previous PR #24036.
Similar fix for
transform()method.