Preserve trailing zeros in Money and RoundedMoney (#438)#444
Open
joao-loureiro-ig wants to merge 1 commit into
Open
Preserve trailing zeros in Money and RoundedMoney (#438)#444joao-loureiro-ig wants to merge 1 commit into
joao-loureiro-ig wants to merge 1 commit into
Conversation
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.
Fixes #438.
Problem
See #438 for details.
Change
ConvertBigDecimal— makeNumber→BigDecimalconversion faithful (removestripScalingZeroes). This alone makesMoneyandRoundedMoneypreserve scale on construction,getNumber()read-back, the amount-factory path, and arithmetic results, with no changes needed toMoney/RoundedMoney.FastMoney's behaviour is intentionally unchanged. Its fixed-scale long representation is lossy (1.42and1.420both map to142000), so it cannot carry trailing zeros. The stripping it used to get implicitly is moved intoMoneyUtils.stripScalingZeroes(...)and applied explicitly where needed, keeping its behaviour identical.Behavioural notes
toString()now shows preserved zeros forMoney/RoundedMoney(e.g."USD 1.420","CHF 1234.0").BigDecimal's natural scale (e.g. a remainder may read as0.5000000000000000;1000 × 28.456 → 28456.000).NumberValue.getAmountFractionNumerator()returns along, so for a factory-builtMoneyat very high scale it can now throw on overflow where stripping previously reduced the scale (the spec permits exact-style accessors to throw on non-representable values).This change is