.calculator-container {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-title {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.calculator-form {
display: grid;
grid-template-columns: 1fr;
gap: 15px;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.calculator-form button {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 4px;
background-color: #fff;
text-align: center;
font-size: 18px;
color: #333;
min-height: 50px; /* Ensure it has some height even when empty */
}
.calculator-result strong {
color: #4CAF50;
}
function calculateEMI() {
var loanAmount = parseFloat(document.getElementById("loanAmount").value);
var annualInterestRate = parseFloat(document.getElementById("annualInterestRate").value);
var loanTenure = parseFloat(document.getElementById("loanTenure").value);
var resultDiv = document.getElementById("result");
// Clear previous results and errors
resultDiv.innerHTML = "";
// Validate inputs
if (isNaN(loanAmount) || loanAmount <= 0) {
resultDiv.innerHTML = "
Please enter a valid loan amount.";
return;
}
if (isNaN(annualInterestRate) || annualInterestRate < 0) {
resultDiv.innerHTML = "
Please enter a valid annual interest rate.";
return;
}
if (isNaN(loanTenure) || loanTenure <= 0) {
resultDiv.innerHTML = "
Please enter a valid loan tenure in years.";
return;
}
// Calculate monthly interest rate
var monthlyInterestRate = annualInterestRate / 12 / 100;
// Calculate number of months
var numberOfMonths = loanTenure * 12;
var emi;
// Handle case for 0% interest rate
if (monthlyInterestRate === 0) {
emi = loanAmount / numberOfMonths;
} else {
// Calculate EMI using the formula: P * r * (1+r)^n / ((1+r)^n – 1)
emi = loanAmount * monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfMonths) / (Math.pow(1 + monthlyInterestRate, numberOfMonths) – 1);
}
// Format EMI to two decimal places
var formattedEMI = emi.toFixed(2);
// Calculate total interest and total payment
var totalPayment = emi * numberOfMonths;
var totalInterest = totalPayment – loanAmount;
resultDiv.innerHTML = "Monthly EMI:
₹ " + formattedEMI + "" +
"Total Interest Payable:
₹ " + totalInterest.toFixed(2) + "" +
"Total Payment:
₹ " + totalPayment.toFixed(2) + "";
}
Understanding Your EMI
An Equated Monthly Installment (EMI) is a fixed amount that a borrower pays to a lender on a specified date each month. EMIs are commonly used for home loans, car loans, personal loans, and other types of secured and unsecured credit.
The EMI amount is calculated based on three primary factors:
- Loan Principal Amount: This is the initial amount of money borrowed from the lender.
- Interest Rate: This is the rate at which the lender charges interest on the loan amount. It's usually expressed as an annual percentage rate (APR).
- Loan Tenure: This is the duration or the period over which the loan needs to be repaid. It's typically expressed in years.
How EMI is Calculated
The formula used to calculate EMI is:
EMI = P × r × (1 + r)n / ((1 + r)n – 1)
Where:
- P = Principal loan amount
- r = Monthly interest rate (Annual interest rate / 12 / 100)
- n = Loan tenure in months (Loan tenure in years × 12)
Our calculator simplifies this by taking your loan amount, annual interest rate, and tenure in years as inputs, and then performs the necessary conversions and calculations to provide you with your EMI, total interest payable, and total payment.
Example Calculation
Let's consider an example:
- Loan Amount (P): ₹ 10,00,000
- Annual Interest Rate: 8.5%
- Loan Tenure: 10 years
First, we convert the annual interest rate to a monthly rate:
Monthly Interest Rate (r) = 8.5% / 12 / 100 = 0.0070833
Next, we convert the loan tenure to months:
Loan Tenure in Months (n) = 10 years × 12 = 120 months
Now, applying the EMI formula:
EMI = 10,00,000 × 0.0070833 × (1 + 0.0070833)120 / ((1 + 0.0070833)120 – 1)
EMI ≈ ₹ 12,717.10
Total Payment = EMI × Number of Months = ₹ 12,717.10 × 120 = ₹ 15,26,052
Total Interest Payable = Total Payment – Loan Amount = ₹ 15,26,052 – ₹ 10,00,000 = ₹ 5,26,052
This calculator helps you quickly estimate these figures for your specific loan scenario.