I made a calculation in Excel and am trying to use it in PHP. Unfortunately, I do not get the correct total when I'm using the function as I wrote it.
This is the calculation as I am using it in Excel :
2500 / (( 0.25 / 100 ) / ( 1 - ( ( 1 + ( 0.25 / 100 )) ^ -360)))
The function I made for calculating in PHP:
function calculatesum($income, $interestmonthly, $months){
return $income / (( $interestmonthly / 100 ) / ( 1 - ( ( 1 + ( $interestmonthly / 100 ) ) ^ -$months)));
}
The function in PHP returns: '360000000' . But this should be '592.973,4538' .
I'm wondering what I'm doing wrong. Any tips will be welcome!
Already looked into the 'pow' functions, but still getting the same outcome.
Excel uses ^ for calculating the power of a number. PHP uses pow($number, $exponent) for that purpose.
function calculatesum($income, $interestmonthly, $months){
return $income / (( $interestmonthly / 100 ) / ( 1 - ( pow(( 1 + ( $interestmonthly / 100 ) ), -$months))));
}
echo calculatesum(2500,0.25,360);
Output:
592973.4537607
See http://php.net/manual/en/function.pow.php for documentation and examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With