0

I am very new in java dev so it might be a trivial question:

double u130 = (1 / 30);
double q1 = Math.pow(1.025, u130);

the q1 is equal 1.0, but it should be 1.0008234259155

u130 = 0.0 also wrong.

I my understanding double is made for so many decimal places, so where is the problem?

By the way I am testing on Android device, this should be a limitation?!

Thanks

Alexander_F
  • 2,831
  • 3
  • 28
  • 61

2 Answers2

5

1 / 30 is the euclidian division, so the result is 0 (as int).

Instead, you need a real division:

double u130 = 1. / 30;
double q1 = Math.pow(1.025, u130);
rom1v
  • 2,752
  • 3
  • 21
  • 47
0

This should solve your problem :

    double u130 = (1 / (double)30);
    double q1 = Math.pow(1.025, u130);
OBX
  • 6,044
  • 7
  • 33
  • 77