Compound Interest Calculator
The compound interest calculator helps you estimate the future value of an investment or loan based on compound interest. Compound interest is calculated on the initial principal, plus the accumulated interest from previous periods. It's often referred to as "interest on interest." This calculator can help you understand how your money can grow over time with regular contributions and a consistent interest rate.
Calculate
Calculation Results
Future Value:
Total Interest Earned:
function calculateCompoundInterest() {
var principal = parseFloat(document.getElementById("principal").value);
var annualInterestRate = parseFloat(document.getElementById("annualInterestRate").value);
var compoundingFrequency = parseInt(document.getElementById("compoundingFrequency").value);
var additionalContribution = parseFloat(document.getElementById("additionalContribution").value);
var timePeriod = parseInt(document.getElementById("timePeriod").value);
var resultElement = document.getElementById("result");
var futureValueOutputElement = document.getElementById("futureValueOutput");
var totalInterestOutputElement = document.getElementById("totalInterestOutput");
if (isNaN(principal) || isNaN(annualInterestRate) || isNaN(compoundingFrequency) || isNaN(additionalContribution) || isNaN(timePeriod) ||
principal < 0 || annualInterestRate < 0 || compoundingFrequency <= 0 || additionalContribution < 0 || timePeriod <= 0) {
resultElement.innerHTML = "
Calculation Results Please enter valid positive numbers for all fields.";
return;
}
var ratePerPeriod = annualInterestRate / 100 / compoundingFrequency;
var numberOfPeriods = timePeriod * compoundingFrequency;
var futureValue = 0;
var currentPrincipal = principal;
for (var i = 0; i 0 && i % compoundingFrequency === 0) {
currentPrincipal += additionalContribution;
}
currentPrincipal += currentPrincipal * ratePerPeriod;
}
futureValue = currentPrincipal;
var totalInterestEarned = futureValue – principal – (additionalContribution * timePeriod);
futureValueOutputElement.textContent = "$" + futureValue.toFixed(2);
totalInterestOutputElement.textContent = "$" + totalInterestEarned.toFixed(2);
}
#compound-interest-calculator {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
#compound-interest-calculator h2, #compound-interest-calculator h3 {
text-align: center;
color: #333;
}
.calculator-inputs {
margin-top: 20px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 15px;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-group input[type="number"],
.input-group select {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
#compound-interest-calculator button {
display: block;
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-top: 20px;
}
#compound-interest-calculator button:hover {
background-color: #45a049;
}
#result {
margin-top: 30px;
padding: 15px;
background-color: #e8f5e9;
border: 1px solid #a5d6a7;
border-radius: 4px;
}
#result h3 {
margin-top: 0;
color: #2e7d32;
}
#result p {
margin: 5px 0;
color: #333;
}
#result span {
font-weight: bold;
}