BigDecimal equals() versus compareTo()

The answer is in the JavaDoc of the equals() method:html

Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).java

In other words: equals() checks if the BigDecimal objects are exactly the same in every aspect. compareTo() "only" compares their numeric value.api

 

注意:java BigDecimal 比較值大小要用compartTo(x)方法。oracle

相關文章
相關標籤/搜索