# Net Present Value Function

Is there a math function in C# for computing the Net Present Value?
###### Who is Participating?

Commented:
See Financial.NPV method (static)

It's in the Microsoft.VisualBasic namespace, however can be used in C#
0

Commented:

There is a .net class you can use, Microsoft.VisualBasic.Financial, which has a static method named NPV.
0

Commented:
ok, sorry for my double posting.
0

RetiredCommented:
Hi Hojoformo;

Visual C# does not have the function but as the other post state you can import the function from Visual Basic. The function in C# would look like this:

Microsoft.VisualBasic.Financial.NPV(FixedRetRate, ref values);

You must add a reference to the above function by going to the Windows Explorer and right click on References and select Add References and locate Microsoft.VisualBasic and add it to your project.

Here is some sample code to test the function.

// Define money format.
string MoneyFmt = "###,##0.00";
// Define percentage format.
string PercentFmt = "#0.00";

double[] values = new double[5];
values[0] = -70000;
// Positive cash flows reflecting income for four successive years.
values[1] = 22000;
values[2] = 25000;
values[3] = 28000;
values[4] = 31000;

// Use the NPV function to calculate the net present value.
// Set fixed internal rate.
double FixedRetRate = 0.0625;
// Calculate net present value.
double NetPVal = Microsoft.VisualBasic.Financial.NPV(
FixedRetRate, ref values);
string Msg = "The net present value of these cash flows is ";
Msg = Msg + NetPVal.ToString(MoneyFmt);
MessageBox.Show(Msg);       // Display net present value.

The above code came from Microsoft documentation at http://msdn2.microsoft.com/en-us/library/4k3y7xeh.aspx.

Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.