Home > other >  Biweekly and weekly calculation help using javascript
Biweekly and weekly calculation help using javascript

Time:10-21

Good day!

I have a question. I have an auto loan calculator that gets a monthly payment perfectly below

var M; //monthly mortgage payment
var P = amount; //principle / initial amount borrowed
var I = Number(rate) / 100 / 12; //monthly interest rate
var N2 = term;
M2 = monthlyPayment(P, N2, I);
function monthlyPayment(p, n, i) {
    return p * i * (Math.pow(1   i, n)) / (Math.pow(1   i, n) - 1);
}

I am running into an issue getting the correct biweekly and monthly payment. I assumed that if term was 26 payments (for one year biweekly as an example) and I replaced the 12 in variable I to 18 ... it would work, but to no avail. Can anyone give me an idea what I am doing wrong?

CodePudding user response:

Math isn't my strongest subject, but you are essentially canceling the value of Math.pow() when you divide it by the exact same value in your second math.pow(). Then you are attempting to subtract it by 1. You are forgetting a bracket.

= (Math.pow(1 i,n)) / (Math.pow(1 i,n)) -1;

CodePudding user response:

I have since learned that U.S. and Canada (where I am from) calculate biweekly payments differently. It was throwing me off since my numbers didn't match some popular online calculators. Many calculators simply make the term for bi weekly 24 payments and the interest variable 24. In Canada the term variable has to be 26 and the interest variable also 26.

  • Related