How to make EMI calculator using C#

This article demonstrate about how to calculate EMI of the loan amount. This example use three textbox controls(loan amount, interest rate and periods In year), one button control with named ‘btnCalculateEMI‘ and one label control named ‘lblMonthlyPayment‘ on which we show monthly payment. Add these control on the windows form like as:

[wpfilebase tag=file id=2]

EMI calculator in C#

Now first we understand formula of EMI calculation:
We use this mathmatical formula for calculating EMI


EMI = [(p*r/12) (1+r/12)^n]/[(1+r/12)^n – 1 ]
where p = principal amount(primary loan amount)
r = rate of interest per year
n = Total number of Years


private void button1_Click(object sender, EventArgs e)
   double LoanAmount = 0;
   double Payment = 0;
   double InterestRate = 0;
   int PaymentPeriods = 0;
       InterestRate = Convert.ToDouble(txtRate.Text);
       PaymentPeriods = Convert.ToInt16(Convert.ToDouble(txtTime.Text) * 12);
       LoanAmount = Convert.ToDouble(txtLoan.Text);
       if (InterestRate > 1)
           InterestRate = InterestRate / 100;
       Payment = (LoanAmount * Math.Pow((InterestRate / 12) + 1,
                 (PaymentPeriods)) * InterestRate / 12) / (Math.Pow         
                 (InterestRate / 12 + 1,(PaymentPeriods)) - 1);
       lblMonthlyPayment.Text = "Monthly Payment: " + Payment.ToString("N2");

In the above you are seeing the ToString() method with the “N2” argument. The numeric (“N”) format specifier converts a number to a string. The precision specifier indicates the desired number of digits after the decimal point. In the above “2” is the precision. For the example id Payment value is 34 then Payment.ToString(“N2”) will be show the “34.00”.

Author: Ankur

Have worked primarily in the domain of Calling, CRM and direct advertisers services. My technological forte is Microsoft Technologies especially Dot Net (Visual Studio 2003, 2005, 2008, 2010 and 2012) and Microsoft SQL Server 2000,2005 and 2008 R2. My Area of Expertise is in C#. Net, VB.Net, MS-SQL Server, ASP. Net, Silverlight, HTML, XML, Crystal Report, Active Reports, Infragistics, Component Art, ComponeOne, Lead Tools etc.

10 thoughts on “How to make EMI calculator using C#”

  1. Sorry to say but i think it shows a wrong output. There is some problem with the formula.
    For e.g. :
    P: 2000
    ROI: 1%
    Time: 300 Months

    Output: 166.67 (Wrong Output)

    Actual Result: 7.54 (Check HDFC & SBI EMI Calculator Online)

  2. Just update if (InterestRate > 1) with if (InterestRate > 0) and you will got the same result as HDFC & SBI EMI Calculator Online.


  3. Hi, I need calculation formula for interest rate of loan. I know the Installment Amount Loan amount and period of loan. So how could i calculate Interest Rate for Quartelly frequency of Payment.

Comments are closed.