Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Math Equation

I am trying to write a math equation with PHP. The equation I need to write is:

(.0054 * 260000) / (1-1.0054^-360)

This equals: 1639.958570 (On my calculator)

With the script I am writing I have it as such:

$dec = .0054;
$amount = 260000;
$months = 360;

$equation = ($dec * $amount) / (1 - (1 + $dec)^-$months);

print $equation;

The answer I am getting when I do this is "-3.9"

Any idea what I'm doing wrong?

like image 254
Jenny Avatar asked Mar 20 '26 14:03

Jenny


2 Answers

Try using the pow() function:

$equation = ($dec * $amount) / (1 - pow(1 + $dec, $months * -1));
like image 56
animuson Avatar answered Mar 23 '26 05:03

animuson


You can not use ^ for power. Whay you are doing now is that you XOR instead.

Use pow for this.

like image 39
alexn Avatar answered Mar 23 '26 04:03

alexn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!