# Re: [PHP] precision using pow()

```Hi,
Split the calculation up an use echo to find the problem.

David Rice wrote:```
```
> Hi:
> I am attempting to calculate a mortgage payment using the following code.
>
> <?PHP
> \$P = 100000;    // principal outstanding
> \$I = 4.5;        // annual interest rate percentage
> \$N = 20;        // number of years
>
> // The formula that I am using
> //(P*(((1+i/200)^(1/6)-1))/(1-(((1+i/200)^(1/6)))^-(n*12)))
>
> \$Pmt =
> \$P*((pow(1+(\$I/200),(1/6))-1)/(1-pow(pow((1+\$I/200),(1/6)),-(\$N*12))));
>
> echo \$Pmt;
> ?>
>
> which produces: 630.40515566726
>
> What I am looking for is 632.65 (rounded to 2 places).
>
> (I am not looking for a rounding mechanism, just a more accurate result)
> The manual states that the pow function attempts to return an Integer.
> Is this the source of the inaccurate result?
>
> The manual also says to look at exp but appears to be missing some
> sort of usage example. I have no idea how that works. I tried a few
> things with no success.
>
> I also came across a mention of bcpow() but am unable to use this in
> the build that I am using.
>
> So is it some boneheaded coding error on my part or am I asking for
> too much of pow()?
>
> Thanks
>
> David
>
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

```