Skip to content

Preserve trailing zeros in Money and RoundedMoney (#438)#444

Open
joao-loureiro-ig wants to merge 1 commit into
JavaMoney:masterfrom
joao-loureiro-ig:fix/issue-438-trailing-zeros
Open

Preserve trailing zeros in Money and RoundedMoney (#438)#444
joao-loureiro-ig wants to merge 1 commit into
JavaMoney:masterfrom
joao-loureiro-ig:fix/issue-438-trailing-zeros

Conversation

@joao-loureiro-ig

@joao-loureiro-ig joao-loureiro-ig commented Jul 11, 2026

Copy link
Copy Markdown

Fixes #438.

Problem

See #438 for details.

Change

  • ConvertBigDecimal — make NumberBigDecimal conversion faithful (remove stripScalingZeroes). This alone makes Money and RoundedMoney preserve scale on construction, getNumber() read-back, the amount-factory path, and arithmetic results, with no changes needed to Money/RoundedMoney.
  • FastMoney's behaviour is intentionally unchanged. Its fixed-scale long representation is lossy (1.42 and 1.420 both map to 142000), so it cannot carry trailing zeros. The stripping it used to get implicitly is moved into MoneyUtils.stripScalingZeroes(...) and applied explicitly where needed, keeping its behaviour identical.

Behavioural notes

  • toString() now shows preserved zeros for Money/RoundedMoney (e.g. "USD 1.420", "CHF 1234.0").
  • Arithmetic results keep BigDecimal's natural scale (e.g. a remainder may read as 0.5000000000000000; 1000 × 28.456 → 28456.000).
  • NumberValue.getAmountFractionNumerator() returns a long, so for a factory-built Money at 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 Reviewable

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.

Why does Money strip trailing zeros?

1 participant