PHP计算function

我在Excel中做了一个计算,并试图在PHP中使用它。 不幸的是,当我使用函数的时候,我没有得到正确的总和。

这是我在Excel中使用它的计算:

2500 / (( 0.25 / 100 ) / ( 1 - ( ( 1 + ( 0.25 / 100 )) ^ -360))) 

我在PHP中计算的function:

 function calculatesum($income, $interestmonthly, $months){ return $income / (( $interestmonthly / 100 ) / ( 1 - ( ( 1 + ( $interestmonthly / 100 ) ) ^ -$months))); } 

PHP中的函数返回:“360000000”。 但这应该是'592.973,4538'。

我想知道我做错了什么。 任何提示将受到欢迎!

已经研究过“function”的function,但仍然得到相同的结果。

Excel使用^来计算数字的功率。 PHP使用pow($number, $exponent)来达到这个目的。

 function calculatesum($income, $interestmonthly, $months){ return $income / (( $interestmonthly / 100 ) / ( 1 - ( pow(( 1 + ( $interestmonthly / 100 ) ), -$months)))); } echo calculatesum(2500,0.25,360); 

输出:

 592973.4537607 

有关文档和示例,请参阅http://php.net/manual/en/function.pow.php

用这个。 PHP不会使用^来提高权力。 您可以使用提高价值的权力

**

例如,

2 ** 5将等于2 ^ 5

希望这可以帮助。

 function calculatesum($income, $interestmonthly, $months){ return $income / (( $interestmonthly / 100 ) / ( 1 - ( ( 1 + ( $interestmonthly / 100 ) ) ** -$months))); } 

PHP不认为^作为运算符,而是使用另一个函数pow 。 在这里input链接描述我认为这是所有你必须改变,以获得您正在寻找的价值。

 function calculatesum($income, $interestmonthly, $months){ $n1=( $interestmonthly / 100 ); $n2= ( 1 + ( $interestmonthly / 100 ) ); $r1= pow($n2,-$months); $r2=$n1 / ( 1 - $r1); return $income /($n1 /$r2); }