double y1 = 0;
double y2 = 0;
double i = 0.025;
double n = 2;
double h1 = 2000;
double h2 = 4000;
y1 = Math.pow((1 + i), n) * h1;
y2 = Math.pow((1 + i), n) * h2;
double result = y1 + y2;
System.out.println(result);
我想結果爲「6303.749999999999」,但它給了我「6303.75」。我如何解決它?Java舍入(雙)
You _want_' 6303.749999999999'? – Tunaki
[如何在Java中將數字四捨五入爲小數點後n位](http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in- java) – azurefrog
是不是像想要0.999999999999一樣的代碼相同:double a = 1? – ergonaut