I am trying to convert an excel function into php, I am getting stuck on the last bit with exponentiation.

Here is the excel function:

=((E15/12)*(0.75*E12)/((1-(1+(E15/12))^(-(E18*12)))))

Here is the PHP I have created:

$price = 100000;
$rate = 2;
$years_back = 10;

$pay_1_5 = ($rate/12) * (0.75*$price) / ((1-(1+($rate/12))pow(-($years_back*12))));

I cant seem to get the 'pow()' function to work.

有帮助吗?

解决方案

$pay_1_5 = ( $rate / 12 ) * 
           ( 0.75 *  $price ) / 
           ( 1 - pow( 1 + ( $rate / 12), - ( $years_back * 12 )));

EDIT

I've just populated an Excel spreadsheet with your original Excel formula and set cell values for E12 to 100000, E15 to 2 and E18 to 10, and Excel is giving me 12500.00012 as the result.

However, if I set cell E15 to 2% (which would be a $rate value of 0.02) I get a result of 690.1009038.

So you need to adjust your rate value from 2 to 2 / 100... 2% is a lot less userous as an interest rate than 200%

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top