I am trying to convert a string to double using Double.valueOf(String s) function and multiply it by 100. The result works fine for most of the numbers except for some. For example, if the amount is 10.20 and i use Double.valueOf(10.20) * 100, the result is 1019.9999 instead of 1020.0. This only happens for 10.20, 8.20, 9.20. It works fine for 7.20, 1.20, 11.20 etc. What is the reason for this? Below is the snippet of my code
1st scenario
String s = "10.20"; *System.out.println("the value after double manipualtion is" +(Double.valueOf(firstHalf) 100 ));
Result :- the value after double manipualtion is1019.9999999999999
Where as the actual result should be 1020.0. If i give the following, it works fine
2nd Scenario
*String s = "7.20"; System.out.println("the value after double manipualtion is" +(Double.valueOf(firstHalf) 100 ));
Result:- the value after double manipualtion is720.0
Any help would be appreciated