how to calculate mortgage in javascript

a 夏天 提交于 2019-12-03 03:28:37
shay

Here is mine,

the formula :

M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]

nerdWallet

Hope this helps in someway

var M; //monthly mortgage payment
var P = 400000; //principle / initial amount borrowed
var I = 3.5 / 100 / 12; //monthly interest rate
var N = 30 * 12; //number of payments months

//monthly mortgage payment
M = monthlyPayment(P, N, I);

console.log(M);

function monthlyPayment(p, n, i) {
  return p * i * (Math.pow(1 + i, n)) / (Math.pow(1 + i, n) - 1);
}
var deno = (100 + Interest_rate_per_annum)/100;
var pdeno = Math.pow(deno, Term_of_Loan);
var loan_amount = (Monthly_payment * Term_of_Loan * 12) / pdeno;

This is the exact same answer as @shay gave but with the variable names spelled out to make it easier for me to understand:

// totalPayments should be the total number of payments expected to be made for the life of the loan: years * 12
// interestRate: eg. 6.2% should be passed as 0.062
function getMortgagePayment(startingLoanAmount, totalPayments, interestRate)
{
    let interestRatePerMonth = interestRate / 12;
    return startingLoanAmount * interestRatePerMonth * (Math.pow(1 + interestRatePerMonth, totalPayments)) / (Math.pow(1 + interestRatePerMonth, totalPayments) - 1);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!