how to calculate mortgage in javascript

后端 未结 3 948
执念已碎
执念已碎 2021-02-06 11:13

I have formula for finding monthly payment with four fields

  1. Loan Amount
  2. Interest Rate
  3. Terms of loan
  4. Monthly Payment

3条回答
  •  借酒劲吻你
    2021-02-06 12:09

    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);
    }
    

提交回复
热议问题