Comparison between decimal type data and BigDecimal in the database

Comparison between decimal type data and BigDecimal in the database

method one:

Reason: the difference between 0 and 0.000000000…

a.getNumber.equals(new Bigdecimal(0));     错误
Method Two:

Reason: the difference between 0 and 0.000000000…

a.getNumber.equals(BigDecimal.ZERO);       错误
Method three:

The results of the first two methods cannot be compared. Method two is occasionally correct, and occasionally wrong. Decimal points are generally used for amounts, so be careful and cautious.
And don't look at the type in the database is decimal, which is different from BigDecimal in java.

a.getNumber.compareTo(BigDecimal.ZERO);          叮咚,正确

おすすめ

転載: blog.csdn.net/qq_44681872/article/details/125392873