先看看几行代码:

public class BigDecimalTest {
    public static void main(String[] args) {
        BigDecimal test = new BigDecimal("0.0");
        System.out.println("equals   方法判断是否为0:" +test.equals(BigDecimal.ZERO));
        System.out.println("compareTo方法判断是否为0:" + (test.compareTo(BigDecimal.ZERO) == 0));
    }
}

其运行结果让我很是诧异,本来我以为两个都是true,但是结果并不是这样:

"C:\Program Files\Java\jdk1.8.0_171\bin\java.exe""......
equals   方法判断是否为0:false
compareTo方法判断是否为0:true

Process finished with exit code 0