Created
March 30, 2023 14:37
-
-
Save daigofuji/7bc42b95c4d83b86de5562188c484fdf to your computer and use it in GitHub Desktop.
amortization formula in JavaScript
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
// P: principal (loan amount) | |
// r: monthly interest rate | |
// M: monthly payment | |
// n: number of months | |
const P = 10000; // example loan amount | |
const r = 0.015; // example monthly interest rate (18% APR / 12 months) | |
const M = 100; // example monthly payment amount | |
let n = Math.log(M / (M - r * P)) / Math.log(1 + r); // calculate number of months | |
n = Math.ceil(n); // round up to the nearest whole number | |
console.log(n); // output: the number of months to pay off the loan with fixed monthly payments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment