function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vadm SfVadm Sf 

Net Present Value in the controller

Hello Experts,

Can you please help me placing the below formula on VF Controller Page.

The following is the formula for calculating NPV: 
User-added image
Ct = net cash inflow during the period
Co= initial investment
r = discount rate, and
t = number of time periods 

Thank you so much .
 
GautamKumarDrefGautamKumarDref
public class sampleController{

public static void cal{
Decimal Ct;
Decimal C0;
Decimal r;
Integer t,i;

Decimal myDecimal = 1+r;

Decimal decValue = myDecimal.pow(t);

Decimal fractionValue = (ct/decValue)-C0;

Decimal finalValue=0.00;

for(i=1;i<=t;i++){

finalValue+=fractionValue;

}

}
}
HI Vadm,

You can change the data type to double if that's your req. But this should work fine with some minor tweaking.

Thanks,

Gautam Kumar.