Skip to content

Instantly share code, notes, and snippets.

@eivindingebrigtsen
Created December 2, 2010 14:10
Show Gist options
  • Save eivindingebrigtsen/725345 to your computer and use it in GitHub Desktop.
Save eivindingebrigtsen/725345 to your computer and use it in GitHub Desktop.
$.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