Search code examples
kotlinkotlin-exposed

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

  • 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.