I have a bit of problem with the double accuracy. E.g
double os = 0.05; os += 0.05; os += 0.05; System.out.println(os);
And I get 0.150000000002 (or something)
I aleardy tried this program with various jdk versions and platforms and still get the same result. Of course the accuracy of the computation is not affected, but it is a small inconvinience for outputting purposes.
Anyone knows how to get 0.15 for the above code?
Joined: Mar 11, 2002
Avoid float & double for any calculations that require an exact answer. Use BigDecimal instead. Or, if you are not worried about the exact answer but your only concern is to display the result properly, you can use DecimalFormat.