Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP计算函数_Php_Excel - Fatal编程技术网

PHP计算函数

PHP计算函数,php,excel,Php,Excel,我在Excel中做了一个计算,并试图在PHP中使用它。不幸的是,当我使用我编写的函数时,我没有得到正确的总数 这是我在Excel中使用的计算: 2500 / (( 0.25 / 100 ) / ( 1 - ( ( 1 + ( 0.25 / 100 )) ^ -360))) 我用PHP编写的计算函数: function calculatesum($income, $interestmonthly, $months){ return $income / (( $interestmonthly

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

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

2500 / (( 0.25 / 100 ) / ( 1 - ( ( 1 + ( 0.25 / 100 )) ^ -360)))
我用PHP编写的计算函数:

function calculatesum($income, $interestmonthly, $months){
   return $income / (( $interestmonthly / 100 ) / ( 1 - ( ( 1 + ( $interestmonthly / 100 ) ) ^ -$months)));
}
PHP中的函数返回:“360000000”。但这应该是“592.9734538”

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


已经研究了“pow”函数,但仍然得到相同的结果。

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

有关文档和示例,请参阅。

使用此选项。PHP不会使用^来提高功耗。您可以使用

**

比如说,

2**5等于2^5

希望这有帮助

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

PHP不考虑^作为运算符,而是使用另一个函数<强> POW。 我认为这就是你所要改变的一切,以获得你想要的价值

函数计算um($income,$interestmonthly,$months){
$n1=(每月利息$100);
$n2=(1+($interestmonthly/100));
$r1=战俘($n2,-$month);
$r2=$n1/(1-$r1);
返回$income/($n1/$r2);

}
您在代码中使用“^”的目的是什么?@user5237857,^表示数字的幂。(例如2^5=2*2*2*2*2)我知道你可能已经解决了这个问题,所以我的答案与此无关。嘿@maxhb非常感谢你的解决方案。它就像一个符咒。我将研究pow函数。