Search code examples
javabigdecimal

How to compare three BigDecimal values


I need to compare three Bigdecimal values like this. Eg:

    if(Min<=Value<=Max){
     //Do this
    }else{
     //Do this
    }

All three values are BigDecimals.How to compare like this in Java. Thanks. Anuradha.


Solution

  • You need to use compareTo. The example you provide would be:

    if(Min.compareTo(Value)<=0 && Max.compareTo(Value) >=0){
         //Do this
        }else{
         //Do this
        }