How to check if BigDecimal variable == 0 in java?

后端 未结 11 609
灰色年华
灰色年华 2020-12-04 06:29

I have the following code in Java;

BigDecimal price; // assigned elsewhere

if (price.compareTo(new BigDecimal(\"0.00\")) == 0) {
    return true;
}
<         


        
11条回答
  •  清歌不尽
    2020-12-04 06:55

    I usually use the following:

    if (selectPrice.compareTo(BigDecimal.ZERO) == 0) { ... }
    

提交回复
热议问题