Skip to content
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

[4.x] Use RationalMoney when computing modifier totals #16

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

voidgraphics
Copy link
Member

When working with modifiers, calling $amount = $amount->plus($modification['amount']); when computing the total value for the modifiers sometimes results in a RoundingNecessaryException (Rounding is necessary to represent the result of the operation at this scale).

This is because the amount of the modifier can return a RationalMoney amount, and the total amount is instanciated as a regular Money object, so it does not know how to handle rounding by default.

This PR fixes it by instanciating the total as a RationalMoney object instead, which does not result in a rounding exception. This may be a breaking change, but it's the only way we can allow modifiers to return a RationalMoney value without crashing.


This PR is intended for 4.x-beta versions, but the 4.x stable release will feature a broader rework to move towards a more complete RationalMoney usage.

See #15

@voidgraphics voidgraphics merged commit 50bbf15 into master Sep 16, 2024
6 checks passed
@voidgraphics voidgraphics deleted the fix-modifiers-rational-money branch September 16, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant