'koltin exposed - compare BigDecimal / decimal column with zero

how should i verify, if a decimal / BigDecimal columt type is zero?

fun foo():Op<Boolean> = UserTable.debt eq BigDecimal.ZERO

I want to avoid this kind of comparison:

BigDecimal("0.00").equals(BigDecimal.ZERO)


Solution 1:[1]

As far as I understand, you want to avoid the problem where equivalent BigDecimals in Java are not considered equal because of trailing zeros.

Note that the actual comparison will be performed by the database. If you are using PostgreSQL, the comparison via eq is correct. It is probably correct for other databases, but you should consult the documentation for your database and/or perform some tests to make sure that the comparison behaves the way you expect.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mikhail Burshteyn