Compound interest is the interest earned on both the initial principal and the accumulated interest from previous periods. It's often referred to as "interest on interest," and it's a powerful tool for growing wealth over time. The longer your money is invested, the more significant the effect of compounding becomes.
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
Annually
Semi-annually
Quarterly
Monthly
Daily
Results:
function calculateCompoundInterest() {
var principal = parseFloat(document.getElementById("principal").value);
var annualRate = parseFloat(document.getElementById("annualRate").value);
var compoundingFrequency = parseInt(document.getElementById("compoundingFrequency").value);
var years = parseFloat(document.getElementById("years").value);
if (isNaN(principal) || isNaN(annualRate) || isNaN(compoundingFrequency) || isNaN(years) ||
principal <= 0 || annualRate < 0 || compoundingFrequency <= 0 || years <= 0) {
document.getElementById("futureValue").innerHTML = "Please enter valid positive numbers for all fields.";
document.getElementById("totalInterest").innerHTML = "";
return;
}
var ratePerPeriod = annualRate / 100 / compoundingFrequency;
var numberOfPeriods = compoundingFrequency * years;
var futureValue = principal * Math.pow((1 + ratePerPeriod), numberOfPeriods);
var totalInterest = futureValue – principal;
document.getElementById("futureValue").innerHTML = "Future Value: $" + futureValue.toFixed(2);
document.getElementById("totalInterest").innerHTML = "Total Compound Interest Earned: $" + totalInterest.toFixed(2);
}