Created
December 2, 2010 14:10
-
-
Save eivindingebrigtsen/725345 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.getAnnuiPayment = function(amount, months, rate) { | |
/* Calculates the monthly payment from annual percentage | |
rate, term of loan in months and loan amount. **/ | |
var interest = 0.0; | |
var principal = 0.0; | |
var acc = 0; | |
var base = 1 + rate / 1200; | |
for (var i = 1; i <= months; i++) { | |
acc += Math.pow(base, -i); | |
} | |
var payment = (amount / acc); | |
interest = amount * rate / 1200; | |
principal = payment - interest; | |
return { | |
pay: payment, | |
fee: $.termfee, | |
principal: principal, | |
interest: interest | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment