Bigdecimal

Bigdecimal运算处理null

        BigDecimal num1 = null; // 或者其他的 BigDecimal 对象
        BigDecimal num2 = new BigDecimal("5.5");
        BigDecimal result = (num1 != null ? num1 : BigDecimal.ZERO).subtract(num2);

Bigdecimal 比较是否等于0

 BigDecimal number = new BigDecimal("0.00");

        if (number.compareTo(BigDecimal.ZERO) == 0) {
            System.out.println("The number is equal to 0");
        } else {
            System.out.println("The number is not equal to 0");
        }

你可能感兴趣的:(Java,java)