Because of floating point imprecision, the BigDecimal(double)
constructor can be somewhat unpredictable. It is better to use BigDecimal.valueOf(double)
.
Apply with the Grit CLI
grit apply no_big_decimal_double
Transforms BigDecimal constructor with double argument
BEFORE
double d = 1.1; BigDecimal bd1 = new BigDecimal(d); BigDecimal bd2 = new BigDecimal(1.1);
AFTER
double d = 1.1; BigDecimal bd1 = BigDecimal.valueOf(d); BigDecimal bd2 = BigDecimal.valueOf(1.1);