Jo Do Jo Do - 11 days ago 7
PHP Question

How can I do this calculation in php?

I want to do this calculation in PHP:

10000*(0.011*(1.1^148))


If I run this through a calculator the result is
147065257,797835
(I want to round it to
147070000
.)

I ran this in PHP

echo round(10000*(0.011*(1.1^148)), 1);


and the output was
16390
. Why does it show a completly different result from my calculator? What can I change to make the result to
147065257,797835
?

Answer

The exponential expression is used as function and not with caret as shown below:

$sum = 10000*(0.011*pow(1.1, 148));

echo round($sum, -4);

I've also corrected your rounding for the desired output.

http://php.net/manual/en/function.pow.php

http://php.net/manual/en/function.round.php