When you create a double, a value of 0.3 cannot be represented exactly. You can create a BigDecimal from a string without an intermediate double, as in
new BigDecimal("0.3")
A floating point number is represented as a binary fraction and exponent. Therefore, there is a certain number that cannot be accurately represented. There is a similar problem in base 10 with numbers like 1/3, which is 0.3333333333 ..... Any decimal representation 1/3 is inaccurate. This happens with a VARIOUS set of fractions in binary format, and 0.3 is one of the set that is inaccurate in binary format.
source share