Most finite decimal fractions cannot be exactly represented by floating-point, so that is the approximation you get when you create the floating-point literal 0.0077
.
To avoid the problem, use the constructor BigDecimal(String val)
instead:
BigDecimal lat = new BigDecimal("0.0077");
As @TimB points out, if you already have a double
value, you can also use:
BigDecimal lat = BigDecimal.valueOf(doubleVal);
Also, here is the mandatory reference to What Every Computer Scientist Should Know About Floating-Point Arithmetic.