BigDecimal adding wrong value

Use a String literal:

private static final BigDecimal sd = new BigDecimal("0.7");

If you use a double, actually public BigDecimal(double val) is called. The reason you do not get 0.7 is that it cannot be exactly represented by a double. See the linked JavaDoc for more information.

Leave a Comment