I was searching for a precise way to multiply two floating point numbers in Java, and I read that I should use BigDecimal, however it doesn't work as expected. What am I doing wrong?
My code:
BigDecimal a = new BigDecimal(3.53);
BigDecimal b = new BigDecimal(3.59);
BigDecimal c = a.multiply(b);
System.out.println(c);
Result:
12.672699999999998796873512674210388041622697702955394242845497954075284496866515837609767913818359375
Expected result:
12.6727