PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Regit
Forum Newbie
Posts: 11 Joined: Tue Oct 10, 2006 7:36 am
Location: Here, there, everywhere
Post
by Regit » Thu Oct 19, 2006 3:51 pm
I am trying to use the following class to produce the npv (Net Pressent Value) of some numbers. I am using this for a custom app for our accounting office.
Code: Select all
class npv {
function calcNPV($rate, $values) {
for ($i=0;$i<=count($values);$i+=1) {
$npv = $values[count($values) - $i] + $npv / (1 + $rate);
}
return $npv;
}
}
// using the function
$npv = new npv();
print $npv->calcNPV(0.09, array(0,30,40,50,60,70));
what am I doing wrong, or is there another way to calculate NPV?
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Oct 19, 2006 3:56 pm
Could you help us help you by stating the problem a little more clearly%AC What is not working%AC How is it not working%AC Please be specific.
Regit
Forum Newbie
Posts: 11 Joined: Tue Oct 10, 2006 7:36 am
Location: Here, there, everywhere
Post
by Regit » Thu Oct 19, 2006 3:59 pm
Yes sorry, All that happens is it prints
calcNPV(0.09, array(0,30,40,50,60,70)); } ?>
to the screen, it doesnt print the npv value
Regit
Forum Newbie
Posts: 11 Joined: Tue Oct 10, 2006 7:36 am
Location: Here, there, everywhere
Post
by Regit » Thu Oct 19, 2006 4:03 pm
We'll I figured out what I needed to do, so there is now no problem. Thx for trying to help though, i appreciate it