JavaMoney / jsr354-ri

JSR 354 - Moneta: Reference Implementation
Other
343 stars 101 forks source link

`RoundingMode` of `DefaultRoundingProvider` hardcoded to `HALF_EVEN` #408

Open jurriaan opened 8 months ago

jurriaan commented 8 months ago

I've set the org.javamoney.moneta.Money.defaults.roundingMode property to HALF_UP but noticed that the rounding using Monetary.getDefaultRounding() still used HALF_EVEN when rounding.

I think this is due to the DefaultRoundingProvider having the default roundingMode set to HALF_EVEN instead of using the configuration.

See: https://github.com/JavaMoney/jsr354-ri/blob/3415a66a09326f8e8bf07c21213b4d7eb4cf561a/moneta-core/src/main/java/org/javamoney/moneta/spi/DefaultRoundingProvider.java#L59

Is this expected behavior?

kewne commented 6 months ago

Is that property documented anywhere? As far as I can tell, the spec compliant way to get a rounding with a client defined rounding mode is:

RoundingQueryBuilder.of()
  .set(RoundingMode.class, RoundingMode.HALF_Up)
  .build();

Edit: Just looked at org.javamoney.moneta.Money.defaults.roundingMode. This should only affect rounding when Money instances are used, and even then it's only used when the result of an operation exceeds the precision.