Compound Interest Formula

Description: Calculates the value of an investment provided the initial principal, percentage rate, compoundings per year over a certain number of years.
Tested Platform: All modern browsers
Language: Javascript
// Simple compound interest formula. 
// Provide initial principal, annual rate (as percentage), number of compoundings over years.
// Remember to round appropriately for money.

function compoundInterest(principal, annualRate, compoundings, years) {
    return principal * Math.pow(1 + ((annualRate / 100) / compoundings), compoundings * years);

Posted: March 20, 2023

Return to the snippets listing