Skip to content

MonetaryAmount.stripTrailingZeros() is confusing #114

Open
@marschall

Description

@marschall

javax.money.MonetaryAmount#stripTrailingZeros() is confusing for two reasons:

  • It seems to be the only method left on MonetaryAmount that operates on the number value. #getAmountWhole() has been removed and #getAmountFractionNumerator() and #getAmountFractionDenominator() have been moved to javax.money.NumberValue.
  • It assumes the implementation has an adjustable scale like BigDecimal/org.javamoney.moneta.Money. It is unspecified that should happen in cases where the scale is fixed like for org.javamoney.moneta.FastMoney.

It could either be moved to javax.money.NumberValue like #getAmountFractionNumerator() and #getAmountFractionDenominator() or a user could simply do

money.getFactory()
        .setNumber(money.getNumber().numberValueExact(BigDecimal.class).stripTrailingZeros())
        .create();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions