Simple Interest Calculator
This calculator helps you determine the simple interest earned on an investment or the simple interest paid on a loan. Simple interest is a basic method of calculating the interest charge on a loan. It is determined by multiplying the daily interest rate by the principal by the number of days that elapse between payments. Simple interest is calculated using the formula: Interest = Principal × Rate × Time
Principal: The initial amount of money borrowed or invested.
Rate: The annual interest rate (expressed as a decimal).
Time: The duration of the loan or investment, in years.
.calculator-container {
font-family: Arial, sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 400px;
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;
font-size: 0.9em;
}
.calculator-inputs {
margin-top: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
color: #444;
font-weight: bold;
}
.form-group input {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
.calculator-inputs button {
display: block;
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
}
.calculator-inputs button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 4px;
background-color: #e9ecef;
text-align: center;
font-size: 1.1em;
color: #333;
min-height: 50px; /* To prevent layout shifts */
display: flex;
align-items: center;
justify-content: center;
}
function calculateSimpleInterest() {
var principal = parseFloat(document.getElementById("principal").value);
var rate = parseFloat(document.getElementById("rate").value);
var time = parseFloat(document.getElementById("time").value);
var resultDiv = document.getElementById("result");
if (isNaN(principal) || isNaN(rate) || isNaN(time) || principal <= 0 || rate < 0 || time <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
// Convert rate from percentage to decimal
var decimalRate = rate / 100;
// Calculate simple interest
var interest = principal * decimalRate * time;
// Calculate total amount
var totalAmount = principal + interest;
resultDiv.innerHTML = "
Results:
" +
"
Simple Interest Earned/Paid: $" + interest.toFixed(2) + "" +
"
Total Amount (Principal + Interest): $" + totalAmount.toFixed(2) + "";
}