I dont know how to handle new BigDecimal("0E30"). Its value is 0 but it doesn’t compare to BigDecimal.ZERO. See below:
System.out.println(new BigDecimal("0E30").add(BigDecimal.ONE)); // ---> 1
System.out.println(new BigDecimal("0E30").equals(BigDecimal.ZERO)); // ---> false
Could someone help me to make the comparison true (I know I can get a workaround by converting the BigDecimals to double, but I would like to know what is going on)?
I am using JRE 1.6.3.
thanks
From the docs (emphasis is mine):
In this case, the scale doesn’t match. So instead, you should use
compareTo().BigDecimalis one of the cases whereequals()is inconsistent withcompareTo():