How Car Loan EMI Is Calculated: A Small JavaScript Function You Can Test
Every loan screen in India shows one number in bold: the EMI. Behind it sits a single formula, and once you can compute it yourself you can sanity-check any quote a lender or dealer gives you. The formula EMI
Every loan screen in India shows one number in bold: the EMI. Behind it sits a single formula, and once you can compute it yourself you can sanity-check any quote a lender or dealer gives you.
The formula
EMI = P Γ r Γ (1 + r)^n / ((1 + r)^n β 1)
- P is the principal (the amount you borrow)
- r is the monthly interest rate: annual rate Γ· 12 Γ· 100
- n is the number of monthly instalments
The most common bug is passing the annual rate straight in. 11% a year is 0.0091667 a month, not 0.11.
In JavaScript
function emi(principal, annualRatePct, months) {
const r = annualRatePct / 12 / 100;
if (r === 0) return principal / months; // zero-interest edge case
const f = Math.pow(1 + r, months);
return (principal * r * f) / (f - 1);
}
console.log(emi(500000, 11, 48).toFixed(2)); // 12922.76
A βΉ5,00,000 loan at 11% for 48 months comes to about βΉ12,923 a month. Over four years you pay βΉ6,20,304, so βΉ1,20,304 of that is interest.
Where the money goes each month
The EMI stays fixed, but the split between interest and principal shifts every month. Interest is charged on the balance still outstanding, so early instalments are interest-heavy:
function schedule(principal, annualRatePct, months) {
const r = annualRatePct / 12 / 100;
const pay = emi(principal, annualRatePct, months);
let balance = principal;
const rows = [];
for (let m = 1; m <= months; m++) {
const interest = balance * r;
const towardPrincipal = pay - interest;
balance -= towardPrincipal;
rows.push({
month: m,
interest: +interest.toFixed(2),
principal: +towardPrincipal.toFixed(2),
balance: +Math.max(balance, 0).toFixed(2),
});
}
return rows;
}
console.table(schedule(500000, 11, 48).slice(0, 3));
| Month | Interest | Principal | Balance |
|---|---|---|---|
| 1 | 4,583.33 | 8,339.43 | 4,91,660.57 |
| 2 | 4,506.89 | 8,415.87 | 4,83,244.70 |
| 3 | 4,429.74 | 8,493.02 | 4,74,751.68 |
That's why a prepayment early in the loan saves far more interest than the same prepayment near the end.
Tenure is the lever people underestimate
Same βΉ5,00,000 loan, same 11% rate:
| Tenure | EMI | Total interest |
|---|---|---|
| 36 months | βΉ16,369 | βΉ89,284 |
| 48 months | βΉ12,923 | βΉ1,20,304 |
| 60 months | βΉ10,871 | βΉ1,52,260 |
Going from 3 years to 5 cuts the EMI by about a third but adds roughly βΉ63,000 in interest.
Gotchas if you build this into an app
- Rounding. Lenders round the EMI to the rupee and adjust the last instalment, so don't expect your schedule to land on exactly zero.
- Floating point. Round for display at the end, not at every step, or the errors pile up.
- Flat vs reducing rate. This formula is for reducing-balance loans. A "flat rate" quote charges interest on the original principal for the whole term, so the effective rate is much higher than the number quoted.
- Fees. Processing fees and bundled insurance aren't in the formula. Add them separately to get the true cost.
Cross-checking your output
If you want to compare your function against a ready-made tool, Hooter's car EMI calculator is handy for a quick check. For the non-code side of second-hand car finance (lender types, documents, typical tenures), their used car loan guide covers the basics.
Disclosure: I work with Hooter, a used-car marketplace in Delhi NCR. The code above is standalone and free to reuse.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.