Compound Interest Calculator
Compound interest is the interest calculated on the initial principal, which also includes all of the accumulated interest from previous periods. It's often referred to as "interest on interest." This can significantly boost your savings and 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
Principal Amount ($):
Annual Interest Rate (%):
Compounding Frequency (times per year):
Annually
Semi-annually
Quarterly
Monthly
Weekly
Daily
Number of Years:
Calculate
.calculator-container {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-container p {
color: #555;
line-height: 1.6;
margin-bottom: 10px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"],
.form-group select {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
.form-group button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
width: 100%;
}
.form-group button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
padding: 15px;
background-color: #e7f3fe;
border-left: 6px solid #2196F3;
color: #333;
font-size: 1.1em;
text-align: center;
border-radius: 4px;
}
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);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
if (isNaN(principal) || principal <= 0) {
resultDiv.innerHTML = "Please enter a valid principal amount.";
return;
}
if (isNaN(annualRate) || annualRate < 0) {
resultDiv.innerHTML = "Please enter a valid annual interest rate.";
return;
}
if (isNaN(compoundingFrequency) || compoundingFrequency <= 0) {
resultDiv.innerHTML = "Please select a valid compounding frequency.";
return;
}
if (isNaN(years) || years <= 0) {
resultDiv.innerHTML = "Please enter a valid number of years.";
return;
}
var ratePerPeriod = (annualRate / 100) / compoundingFrequency;
var numberOfPeriods = compoundingFrequency * years;
var futureValue = principal * Math.pow((1 + ratePerPeriod), numberOfPeriods);
var totalInterestEarned = futureValue – principal;
resultDiv.innerHTML =
"
Calculation Results: " +
"
Initial Investment (Principal): $" + principal.toFixed(2) + "" +
"
Annual Interest Rate: " + annualRate.toFixed(2) + "%" +
"
Compounding Frequency: " + getFrequencyText(compoundingFrequency) + "" +
"
Investment Duration: " + years + " years" +
"
Total Future Value: $" + futureValue.toFixed(2) + "" +
"
Total Interest Earned: $" + totalInterestEarned.toFixed(2) + "";
}
function getFrequencyText(frequency) {
switch(frequency) {
case 1: return "Annually";
case 2: return "Semi-annually";
case 4: return "Quarterly";
case 12: return "Monthly";
case 52: return "Weekly";
case 365: return "Daily";
default: return "Unknown";
}
}