<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Instant Calc Hub</title>
    <description>The latest articles on DEV Community by Instant Calc Hub (@instantcalchub).</description>
    <link>https://dev.to/instantcalchub</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263775%2Fa0ab9b65-429b-446e-a1fc-f2d017a16077.png</url>
      <title>DEV Community: Instant Calc Hub</title>
      <link>https://dev.to/instantcalchub</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/instantcalchub"/>
    <language>en</language>
    <item>
      <title>How EMI Is Calculated: Formula, Worked Example and JavaScript</title>
      <dc:creator>Instant Calc Hub</dc:creator>
      <pubDate>Wed, 25 Nov 2026 04:08:10 +0000</pubDate>
      <link>https://dev.to/instantcalchub/how-emi-is-calculated-formula-worked-example-and-javascript-5a6a</link>
      <guid>https://dev.to/instantcalchub/how-emi-is-calculated-formula-worked-example-and-javascript-5a6a</guid>
      <description>&lt;p&gt;If you have ever taken a loan, you have seen the EMI (equated monthly instalment): one fixed amount you pay every month until the loan is cleared. But how is that number worked out? Here is the formula, a worked example, and a few lines of JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  The EMI formula
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EMI = P × r × (1 + r)^n / ((1 + r)^n − 1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;P&lt;/strong&gt; is the loan amount (principal)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;r&lt;/strong&gt; is the monthly interest rate, which is the annual rate divided by 12 and by 100&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;n&lt;/strong&gt; is the number of monthly instalments, which is the loan term in years times 12&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A worked example
&lt;/h2&gt;

&lt;p&gt;Say you borrow ₹5,00,000 at 9% a year for 5 years.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;P = 500000&lt;/li&gt;
&lt;li&gt;r = 9 / 12 / 100 = 0.0075&lt;/li&gt;
&lt;li&gt;n = 5 × 12 = 60&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Putting these into the formula gives an EMI of roughly &lt;strong&gt;₹10,379&lt;/strong&gt; per month.&lt;/p&gt;

&lt;p&gt;Over 60 months you pay about ₹6,22,740 in total, so the interest cost is about ₹1,22,740.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where each payment goes
&lt;/h2&gt;

&lt;p&gt;Every EMI is split between interest and principal, and the split changes over time. In month 1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interest = 500000 × 0.0075 = ₹3,750&lt;/li&gt;
&lt;li&gt;Principal repaid = 10,379 − 3,750 = ₹6,629&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next month, interest is charged on the smaller remaining balance, so a little more of each EMI goes to principal. That is why early payments are mostly interest.&lt;/p&gt;

&lt;h2&gt;
  
  
  The formula in JavaScript
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;calculateEmi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;principal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;annualRatePercent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;annualRatePercent&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// monthly rate&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                   &lt;span class="c1"&gt;// number of instalments&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;principal&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// interest-free loan&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;principal&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;emi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculateEmi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;emi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// about 10379&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things to watch for in your own code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convert the annual percentage to a monthly decimal rate first. This is the most common mistake.&lt;/li&gt;
&lt;li&gt;Handle a 0% rate separately, otherwise you divide by zero.&lt;/li&gt;
&lt;li&gt;Round only for display, not during the calculation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What changes the EMI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;longer term&lt;/strong&gt; lowers the monthly EMI but increases the total interest paid.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;higher rate&lt;/strong&gt; raises both the EMI and the total cost.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;bigger down payment&lt;/strong&gt; reduces P, which lowers everything.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try it without doing the maths
&lt;/h2&gt;

&lt;p&gt;I built a free &lt;a href="https://instantcalchub.com/emi-calculator/" rel="noopener noreferrer"&gt;EMI calculator&lt;/a&gt; at Instant Calc Hub. Enter the loan amount, interest rate and tenure, and it shows the monthly EMI, total interest and total payment, plus a year-wise payment schedule.&lt;/p&gt;

&lt;p&gt;What would you add to a loan calculator? Tell me in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
