Narrow RoundingNecessaryException for Money::of() with int amount#14
Merged
Narrow RoundingNecessaryException for Money::of() with int amount#14
Conversation
b72549c to
e58413e
Compare
When the amount is int and the context only scales (no step division), Money::of() cannot throw RoundingNecessaryException because scaling an integer to higher precision just adds trailing zeros.
e58413e to
78a4c99
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Money::of()is called with anintamount, scaling to higher precision just adds trailing zeros — no rounding neededDefaultContext),new DefaultContext(),new AutoContext(),new CustomContext($scale),new CustomContext($scale, 1)CustomContextwith step > 1 is still treated as potentially throwing (division by step can require rounding)Fixes e.g.
Money::of(500, 'USD', new CustomContext(4, 1))being flagged as throwingRoundingNecessaryException.Test plan
Money::of(100, 'USD')— int + default context = no throwMoney::of(100, $currency)— int + Currency instance = no throwMoney::of(0, 'EUR', new CustomContext(4, 1))— zero = no throwMoney::of(0, $currency)— zero + safe currency = no throwMoney::of(500, 'EUR', new CustomContext(4, 1))— int + step 1 = no throwMoney::of(500, 'EUR', new CustomContext(4))— int + default step = no throwMoney::of(500, 'EUR', new CustomContext(2, 5))— int + step > 1 = may throwMoney::of($string, 'EUR', new CustomContext(4, 1))— string amount = may throw