The answer is in the JavaDoc of the equals()
method:html
Unlike
compareTo
, this method considers twoBigDecimal
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