Search code examples
javabigdecimal

How to do BigDecimal modulus comparison


Im getting confused on how to write a simple modulus comparison if statement. I basically just want to check if x is a multiple of 20 when x is a BigDecimal. Thanks!


Solution

  • if( x.remainder(new BigDecimal(20)).compareTo(BigDecimal.ZERO) == 0 ) {
       // x is a multiple of 20
    }