Re:The Pitfalls of Comparing BigDecimals in Java
by wging on Tuesday June 18, 2024 @12:57AM
(#40714196)
https://docs.oracle.com/en/java/javase/21/docs/api/java.base... is probably a better link (though it's not that different)
Re:The Pitfalls of Comparing BigDecimals in Java
by bsder on Tuesday June 18, 2024 @01:03AM
(#40714211)
Thanks for the link.
Apparently, restricted behavior like I expected is reserved for if you use a MathContext.
> Instead, for the BigDecimal operations taking a MathContext parameter, if the MathContext has a nonzero precision, the set of possible representable values for the result is determined by the precision of the MathContext argument.
Very strange. I would have expected something that is going to be mostly used for currency to not do implicit things by default.
> The BigDecimal class gives its user complete control over rounding behavior. If no rounding mode is specified and the exact result cannot be represented, an exception is thrown ...
- https://docs.oracle.com/javase/8/docs/api/java/math/BigDecim...