Inspectopedia Help

'equals()' called on 'BigDecimal'

Reports equals() calls that compare two java.math.BigDecimal numbers. This is normally a mistake, as two java.math.BigDecimal numbers are only equal if they are equal in both value and scale.


if (new BigDecimal("2.0").equals( new BigDecimal("2.00"))) {} // false

After the quick-fix is applied:

if (new BigDecimal("2.0").compareTo( new BigDecimal("2.00")) == 0) {} // true

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024