gpt4 book ai didi

PHP计算函数

转载 作者:可可西里 更新时间:2023-11-01 00:58:20 25 4
gpt4 key购买 nike

我在 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.973,4538' 。

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

已经查看了“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

参见 http://php.net/manual/en/function.pow.php用于文档和示例。

关于PHP计算函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34746339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com