I was going to try my luck on StackOverflow, but I have a feeling my issue here is on order of operations.
I'm using the loan calculation found here to build a loan calculator for a clients website.
http://teachertech.rice.edu/Participants/bchristo/lessons/carpaymt.html
P ( r / 12 )
-------------------------
(1 - ( 1 + r / 12 ) ^-m )
$$ \frac{P (r/12)}{1 - (1+ r/12)^{-m}} $$
As set up now, I'm finding the sum of the top, sum of the bottom, then dividing.
Here's my fiddle if it makes sense to anyone.
https://jsfiddle.net/9dbhcLrq/
(top)
- rate/12
- loanAmount * (sum of step 1) = topPart
(bottom)
- rate / 12
- 1 + (sum of step 1)
- (sum of step 2) ^ -months
- 1 - (sum of step 3)
Then top/bottom.
My answer differs from the same variables placed in google's auto loan calculator.
I cannot find a problem with my javascript. It must be in the order of ops.
What am I doing wrong?
Your code:
Can be reduced to
but it should return the same number.
You should compare your results with that loan calculator from teachertech.
The google calculator might use a different calculation formula.