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]

Now first we understand formula of EMI calculation:

We use this mathmatical formula for calculating EMI

## [Formula]

**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

## [Code]

private void button1_Click(object sender, EventArgs e) { double LoanAmount = 0; double Payment = 0; double InterestRate = 0; int PaymentPeriods = 0; try { 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"); } catch { } }

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”.

Thanks for the code. It looks great.

Thanks. Nice article. Keep it up.

if (InterestRate > 1) what is > in above code please tell me thanks in advance.

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)

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

Ankur

And also Time should be in no of YEAR.

Thanks. For Help Me.

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.

Payment.ToString(“N2”);

But What is N2 ?

“N2” is for formatting number into 2 decimal places. Suppose if your payment value is 34 then ‘Payment.ToString(“N2”)’ will be show “34.00”.