Given the formula to calculate a monthly mortgage payment:
and these declarations:
How can you code the formula?
A. m = p * (r * Math.pow(1 + r, n) / (Math.pow(1 + r, n) – 1));
B. m = p * ((r * Math.pow(1 + r, n) / (Math.pow(1 + r, n)) – 1));
C. m = p * r * Math.pow(1 + r, n) / Math.pow(1 + r, n) – 1;
D. m = p * (r * Math.pow(1 + r, n) / Math.pow(1 + r, n) – 1);
This is what I got from each calculation.
A) 790.7936267415464 (correct?)
B) -99583.33333333333
C) 415.6666666666667
D) -99583.33333333333
m = p * (r * Math.pow(1 + r, n)) / Math.pow(1 + r, n) – 1);
The answer is A:
p * (r * x / (x – 1))
where x = Math.pow(1 + r, n)