This question already has an answer here:
- Java BigDecimal difference 4 answers
- Why Are Floating Point Numbers Inaccurate? 3 answers
I am convert String value to double and next BigDecimal why result changed?
public static void main(String[] args) {
String sum = "49561500049999950";
System.out.println("Result " + BigDecimal.valueOf(Double.valueOf(sum)));
/*Result 49561500049999952*/
}
new BigDecimal(String val)
. See the Javadoc: docs.oracle.com/javase/7/docs/api/java/math/… – jhamon yesterday