# Function PMT in C# • ### Question

• Hello,

There is a function PMT in Excel and in Microsoft.VisualBasic for calculating the payment for loan based on the constant payment and constant interest rate. Is there a similar function in C# or can i use the one from Microsoft.VisualBasic? What do i use to get this value?

thanks

Thursday, March 27, 2008 11:09 AM

• You can included the Microsoft.VisualBasic namespace and use the Pmt method like this:

using Microsoft.VisualBasic;

...

double pmt = Financial.Pmt(rate,nper,pv,fv,due); // parameters are the same as in VB.NET

Thursday, March 27, 2008 11:33 AM

### All replies

• You can included the Microsoft.VisualBasic namespace and use the Pmt method like this:

using Microsoft.VisualBasic;

...

double pmt = Financial.Pmt(rate,nper,pv,fv,due); // parameters are the same as in VB.NET

Thursday, March 27, 2008 11:33 AM
• Hi Philippe,

I am trying to call pmt function of Financial class as mentioned in above trail forum.

Although after including Microsoft.VisualBasic namespace, I dont see any class named Financial.

Rupali Kothawade Vana Solutions www.vanasolutions.com
Friday, February 19, 2010 8:00 AM
• You need to add reference in your Project to "Microsoft.VisualBasic".

This reference usually points to:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.VisualBasic.dll

Pierre Assis Noronha
Thursday, February 3, 2011 6:12 PM
• Besides making use of a built in function, you can create your own UDF for PMT in C#

Excel and other spreadsheet programs make use of a mathematical equation to calculate the 5 related time value of money functions. These 5 TVM functions include PV, FV, PMT, NPER and RATE

The equation used is as follows

PV (1+RATE)^NPER + PMT (1 + RATE * TYPE ) [{(1+RATE)^NPER - 1}/RATE]  + FV = 0

TYPE is 0 for an ordinary annuity where payments are made or are due at the end of period (loan payments)

TYPE is 1 for an annuity due where payments are made or are due at the start of period (rent payments)

So by manipulating the equation you can write PMT function with code such as

PMT = -RATE * ( FV + PV * Math.pow(1+RATE,NPER)) / ((Math.pow(1+RATE,NPER)-1)*(1+RATE*TYPE));

• Edited by Saturday, August 11, 2012 10:29 PM fixed typo
• Proposed as answer by Wednesday, August 13, 2014 7:43 AM
Friday, August 19, 2011 2:28 PM