Page 1 of 1

Help using excel function in PHP

Posted: Wed Sep 08, 2010 5:55 pm
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.

Re: Help using excel function in PHP

Posted: Wed Sep 08, 2010 8:25 pm
by requinix
I would guess that RATE() is doing something wrong.

Re: Help using excel function in PHP

Posted: Wed Sep 08, 2010 8:33 pm
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.

Re: Help using excel function in PHP

Posted: Thu Sep 09, 2010 11:23 am
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.

Re: Help using excel function in PHP

Posted: Thu Sep 09, 2010 2:34 pm
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.

Re: Help using excel function in PHP

Posted: Thu Sep 09, 2010 6:33 pm
by jamesrk
Fair enough. Thank you for responding.