Help using excel function in PHP

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

Post Reply
jamesrk
Forum Newbie
Posts: 3
Joined: Wed Sep 08, 2010 5:31 pm

Help using excel function in PHP

Post by jamesrk »

Hi,
I am using the Excel Rate(nper,pmt,pv,fv,type,guess) function to determine the interest rate based on the user's loan and payment criteria.

1) This works on my page:

$test = RATE(20*12,-950,100000)*12;
$test2 = number_format($test, 4, '.', ',')*100;

= 9.77%

compare with Excel:
=(RATE(20*12,-950,100000)*12) = 9.77%

2) When I increase nper to 30 (like below), however, I get the wrong result.

$test = RATE(30*12,950,-100000)*12;

= 8.0539952942838E-015

Excel, however, is okay:
=(RATE(30*12,950,-100000)*12) = 10.97%

Can someone tell me what I'm doing wrong? Thank you.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help using excel function in PHP

Post by requinix »

I would guess that RATE() is doing something wrong.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help using excel function in PHP

Post by califdon »

The PHP manual doesn't show any such function as "RATE()". You can't use a function from a totally different program. Apparently your script defines a PHP function called RATE(). Apparently that's where your answer lies.
jamesrk
Forum Newbie
Posts: 3
Joined: Wed Sep 08, 2010 5:31 pm

Re: Help using excel function in PHP

Post by jamesrk »

Hi,

Thank you both for responding. But several other excel functions work, and even this Rate() function works as long as $nper doesn't exceed 240. Does anyone have a work-around or PHP script that will enable me to determine the interest rate on a loan amount based on payment periods, payment, and loan amount? It would be most appreciated.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help using excel function in PHP

Post by califdon »

Let me assure you most emphatically that PHP cannot use Excel functions! It might have some functions with the same names, which may or may not do the same things, but they are NOT Excel functions! If it's not in the PHP manual and you haven't defined it, it won't work in PHP. Period.
jamesrk
Forum Newbie
Posts: 3
Joined: Wed Sep 08, 2010 5:31 pm

Re: Help using excel function in PHP

Post by jamesrk »

Fair enough. Thank you for responding.
Post Reply