Power Function In PHP 4.2.2
| From: | Andrew V. Romero | Date: | Thu, 15 Aug 2002 00:12:25 +0000 |
| Subject: | Power Function In PHP 4.2.2 | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-15268@lists.php.net to get a copy of this message | ||
I have just recently upgraded to PHP 4.2.2 and am trying to get this version to do the following compounding interest problem, which PHP3 had no problem with.
$futureValue = $currentAmount * pow( 1 + ($interestRatePercent/100), $timeInYears);
In PHP4, it issues a warning saying " Invalid argument(s) passed to pow() in C:\Server\Apache Group\Apache2\htdocs\Compound Interest\cinterest.php3 on line 24". In reading about the pow() function, it appears that in PHP 4 the pow function use to return floats whereas now it returns integers. So my first instinct was to try to cast what power returns into a float. So I tried various tests (since I haven't cast in PHP before). I tried everything from:
(float) $futureValue = $currentAmount * pow( 1 + ($interestRatePercent/100), $timeInYears);
to:
$temp = 1 + ($interestRatePercent/100);
echo "<br>$temp to the $timeInYears<br>"; //i.e echos 1.06 to the 2
(float) $temp1 = (float) pow($temp, $timeInYears);
$futureValue = $currentAmount * $temp1;
I am still getting the warning about invalid arguments passed to pow(). So what is the deal here, how am I suppose to do this type of math problem?
Thanks for any help or ideas.
-Andrew V. Romero