Compound Interest Calculator
Understanding compound interest is crucial for growing your investments. 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 essentially "interest on interest." This powerful effect can significantly boost your savings over time, making it a cornerstone of long-term financial planning.
Results
Total Investment Value: $0.00
Total Interest Earned: $0.00
.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;
margin-bottom: 15px;
color: #333;
}
.calculator-inputs {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-group input {
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
}
.calculator-container button {
grid-column: 1 / -1;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-container button:hover {
background-color: #0056b3;
}
.calculator-results {
margin-top: 20px;
padding-top: 15px;
border-top: 1px dashed #ccc;
text-align: center;
}
.calculator-results h3 {
margin-bottom: 10px;
color: #444;
}
.calculator-results p {
margin: 8px 0;
font-size: 1.05rem;
color: #666;
}
.calculator-results span {
font-weight: bold;
color: #007bff;
}
function calculateCompoundInterest() {
var principal = parseFloat(document.getElementById("principal").value);
var annualRate = parseFloat(document.getElementById("annualRate").value);
var compoundingFrequency = parseFloat(document.getElementById("compoundingFrequency").value);
var years = parseFloat(document.getElementById("years").value);
var ratePerPeriod = annualRate / 100 / compoundingFrequency;
var numberOfPeriods = compoundingFrequency * years;
var totalValue = 0;
var totalInterest = 0;
if (!isNaN(principal) && !isNaN(annualRate) && !isNaN(compoundingFrequency) && !isNaN(years) &&
principal > 0 && annualRate >= 0 && compoundingFrequency > 0 && years > 0) {
totalValue = principal * Math.pow((1 + ratePerPeriod), numberOfPeriods);
totalInterest = totalValue – principal;
document.getElementById("totalValue").textContent = "$" + totalValue.toFixed(2);
document.getElementById("totalInterest").textContent = "$" + totalInterest.toFixed(2);
} else {
document.getElementById("totalValue").textContent = "Invalid input";
document.getElementById("totalInterest").textContent = "Invalid input";
}
}