Below is the part of a small EMI calculator code in Android using Java. Whenever i give input as P = 1000000, T = 120 (in months), R = 9.
Result comes: 9000000.0 which is not correct. I think problem is with "Math.pow(1+R,T)" as it results a very big number. I am not sure. Please help me out.
double P = Double.parseDouble(str1);
double T = Double.parseDouble(str2);
double R = Double.parseDouble(str3);
double Emi = P * R * Math.pow(1+R,T) / (Math.pow(1+R,T) - 1);
f.setText("EMI: "+String.valueOf(Emi));
There is nothing wrong with Math.pow()
, here one thing you missed to consider. Here rate of interest is in percentage. So you need to divide R
by 100
.
Just change the formula as below and this will work.
double Emi = (P * (R/100) * Math.pow(1+(R/100),T)) / (Math.pow(1+(R/100),T)-1)
Hope this will help.