Daniel Crook Daniel Crook - 6 months ago 73
Java Question

For loop comparing BigDecimals

I need the loop to repeat as long as BigDecimal d is greater than 0, and neither of these methods seem to be working. Thanks in advance for any advice.

for (d.compareTo(z) < 0 ; ) {


for (BigDecimal d>0) {



To perform the greater than operation you have to use compareTo() method.

 for(d.compareTo(new BigDecimal("0"))>0; ){  //Your code }

Example :

        BigDecimal d = new BigDecimal("10");
        if(d.compareTo(new BigDecimal("0"))>0)
        //this evaluates to true