Division by 0
am 10.03.2010 19:02:38 von garyI have a mortgage amortization script that was working fine,now it seems to
have gone awry. Below is the entire script plus input page. I am getting an
error
Warning: Division by zero in
/home/content/J/a/y/Jayski/html/one2one/Ricksrecursivefuncti ons.php on line
47
Which is (pow($intCalc,$totalPayments) - 1);
Frankly I am not even sure the information is being passed to the script.
Anyone see what I am missing?
Gary
Loan Amount | USD | src="images/help.png" class="noborder"/> |
Type of Loan | class="noborder"/> | |
Term of Loan | Months | src="images/help.png" class="noborder" /> |
Interest Rate | Per Annum | /> |
function amortizationTable($paymentNum, $periodicPayment, $balance,
$monthlyInterest) {
$paymentInterest = round($balance * $monthlyInterest,2);
$paymentPrincipal = round($periodicPayment - $paymentInterest,2);
$newBalance = round($balance - $paymentPrincipal,2);
print "
# If balance not yet zero, recursively call amortizationTable()
if ($newBalance > 0) {
$paymentNum++;
amortizationTable($paymentNum, $periodicPayment, $newBalance,
$monthlyInterest);
} else {
exit;
}
} #end amortizationTable()
# Loan balance
$balance =($_POST['loan_amount']);
# Loan interest rate
$interestRate = ($_POST['int_rate']);
# Monthly interest rate
$monthlyInterest = ("$interestRate / 12");
# Term length of the loan, in years.
$termLength =($_POST['loan_term']);
# Number of payments per year.
$paymentsPerYear = 12;
# Payment iteration
$paymentNumber =($_POST['loan_term']);
# Perform preliminary calculations
$totalPayments = $termLength * $paymentsPerYear;
$intCalc = 1 + $interestRate / $paymentsPerYear;
$periodicPayment = $balance * pow($intCalc,$totalPayments) * ($intCalc -
1) /
(pow($intCalc,$totalPayments) - 1);
$periodicPayment = round($periodicPayment,2);
# Create table
echo "
Payment Number | Balance | Payment | Interest | Principal |
---|
?>
__________ Information from ESET Smart Security, version of virus signature database 4932 (20100310) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php