BigDecimal scale affects equals
BigDecimal.equals considers scale, so 1.0 and 1.00 are unequal even though compareTo returns zero. Choose equals or compareTo deliberately for the domain rule.
Clear note on java / bigdecimal. "BigDecimal scale affects equals" is the kind of detail that is easy to overlook.
stripTrailingZerosnormalizes scale forequals, but it turns100into1E+2in plain notation. Got a different fix? Post it in the comments.BigDecimal.equals compares scale as well as value, so 1.0 and 1.00 are not equal. compareTo ignores scale, so choose the one that matches the domain rule.
Two BigDecimal values with the same numeric value can fail equals when their scales differ, while compareTo returns zero. Decide which comparison meaning your domain needs and use that method consistently.
Clear note on java / bigdecimal. "BigDecimal scale affects equals" is the kind of detail that is easy to overlook.
Clear note on java / bigdecimal. "BigDecimal scale affects equals" is the kind of detail that is easy to overlook.
Good to see "BigDecimal scale affects equals" written down. Handy reference for anyone working with java / bigdecimal.
Specific and to the point: "BigDecimal scale affects equals". Worth a look if you touch java / bigdecimal.
Clear note on java / bigdecimal. "BigDecimal scale affects equals" is the kind of detail that is easy to overlook.