Compound interest is the interest calculated on the initial principal, which also includes all of the accumulated interest from previous periods on a deposit or loan. It's often referred to as "interest on interest." This can significantly accelerate the growth of your investments over time compared to simple interest, where interest is only calculated on the principal amount.
The formula for compound interest is:
A = P (1 + r/n)^(nt)
Where:
A = the future value of the investment/loan, including interest
P = the principal investment amount (the initial deposit or loan amount)
r = the annual interest rate (as a decimal)
n = the number of times that interest is compounded per year
t = the number of years the money is invested or borrowed for
This calculator helps you estimate how your money can grow with compound interest based on your principal, annual interest rate, investment duration, and how often the interest is compounded.
function calculateCompoundInterest() {
var principal = parseFloat(document.getElementById("principal").value);
var interestRate = parseFloat(document.getElementById("interestRate").value) / 100; // Convert percentage to decimal
var time = parseFloat(document.getElementById("time").value);
var compoundingFrequency = parseInt(document.getElementById("compoundingFrequency").value);
var resultElement = document.getElementById("result");
resultElement.innerHTML = ""; // Clear previous results
if (isNaN(principal) || isNaN(interestRate) || isNaN(time) || isNaN(compoundingFrequency) || principal < 0 || interestRate < 0 || time < 0 || compoundingFrequency <= 0) {
resultElement.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Calculate the future value using the compound interest formula
var exponent = compoundingFrequency * time;
var base = 1 + (interestRate / compoundingFrequency);
var futureValue = principal * Math.pow(base, exponent);
// Calculate the total interest earned
var totalInterest = futureValue – principal;
resultElement.innerHTML = "Future Value: $" + futureValue.toFixed(2) + "" +
"Total Interest Earned: $" + totalInterest.toFixed(2);
}