.calculator-container {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.calculator-title {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
.calculator-container button {
width: 100%;
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-result {
margin-top: 25px;
padding: 15px;
border: 1px dashed #007bff;
border-radius: 4px;
background-color: #e7f3ff;
text-align: center;
font-size: 1.1rem;
color: #0056b3;
min-height: 50px; /* To ensure it's visible even when empty */
display: flex;
align-items: center;
justify-content: center;
}
function calculateEMI() {
var principal = parseFloat(document.getElementById("principal").value);
var annualInterestRate = parseFloat(document.getElementById("annualInterestRate").value);
var loanTenure = parseFloat(document.getElementById("loanTenure").value);
var resultDiv = document.getElementById("result");
if (isNaN(principal) || isNaN(annualInterestRate) || isNaN(loanTenure) || principal <= 0 || annualInterestRate <= 0 || loanTenure <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
var monthlyInterestRate = (annualInterestRate / 100) / 12;
var numberOfMonths = loanTenure * 12;
var emi = (principal * monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfMonths)) / (Math.pow(1 + monthlyInterestRate, numberOfMonths) – 1);
if (isNaN(emi)) {
resultDiv.innerHTML = "Calculation error. Please check your inputs.";
return;
}
var formattedEMI = emi.toFixed(2);
var totalPayment = emi * numberOfMonths;
var totalInterest = totalPayment – principal;
resultDiv.innerHTML = "Your EMI: ₹" + formattedEMI + "" +
"Total Interest Payable: ₹" + totalInterest.toFixed(2) + "" +
"Total Payment: ₹" + totalPayment.toFixed(2);
}
Understanding EMI
Equated Monthly Installment (EMI) is a fixed amount that a borrower pays to a lender on a specified date of each month, right from the beginning of the loan till its closure. EMIs are used to repay both the principal amount and the interest component of the loan. The EMI amount remains constant throughout the loan tenure, but the proportion of principal and interest changes with each installment.
How EMI is Calculated:
The formula used to calculate EMI is:
$$EMI = \frac{P \times R \times (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)
Factors Affecting Your EMI:
- Principal Loan Amount (P): A higher principal loan amount will result in a higher EMI.
- Interest Rate (R): A higher interest rate will lead to a higher EMI. This is a significant factor in determining your monthly outflow.
- Loan Tenure (N): A longer loan tenure will result in a lower EMI, but you will end up paying more interest over the life of the loan. Conversely, a shorter tenure means a higher EMI but less overall interest paid.
Example:
Let's consider a loan with the following details:
- Principal Loan Amount (P): ₹5,00,000
- Annual Interest Rate: 9%
- Loan Tenure: 10 years
First, we calculate the monthly interest rate and the number of months:
- Monthly Interest Rate (R) = (9 / 100) / 12 = 0.0075
- Loan Tenure in months (N) = 10 * 12 = 120 months
Now, applying the EMI formula:
$$EMI = \frac{500000 \times 0.0075 \times (1+0.0075)^{120}}{(1+0.0075)^{120} – 1}$$
$$EMI = \frac{500000 \times 0.0075 \times (2.451357)}{(2.451357) – 1}$$
$$EMI = \frac{9192.59}{(1.451357)}$$
$$EMI \approx ₹6,333.17$$
Using this calculator, you can input these figures (Loan Amount: 500000, Annual Interest Rate: 9, Loan Tenure: 10) to see the calculated EMI, total interest, and total payment.