I have researched this topic and I understand I can use a @ sign in front of my function to suppress the warning, however, I would like to understand this more so I know how to program properly. So, once again I bring this same code up that is bewildering me:
<?
function calcMonthlyPayment($amount, $int, $term)
{
$monthly_int = $int/1200; //Monthly Interest J
$total_amt = $amount; //Loan Amount P
$months = $term * (-12); //Length of Note in months N
$payment = $total_amt * $monthly_int / (1 - pow(1+$monthly_int, $months )); //Determining Monthly Payment
$payment = number_format($payment, 2); //Returning Monthly Payment in a dollar amount
return $payment; //Show me the money
}
$check = calcMonthlyPayment(200000, 5.78, 30);
echo "<p>$check</p>"; ?>
This returns $1,170.96 and NO division by zero warning.
I have included functions.php which is where the above code is stored and I have cut and pasted the $check and echo lines into the following page:
<?php
include ('functions.php');
//determine monthly payment
$monthly_payment = calcMonthlyPayment ($amount, $rate, $term);
// Determining the vacancy adjustment
$vacancy_loss = calcVacancyLoss ($rent, $vacancy);
$check = calcMonthlyPayment(200000, 5.78, 30);
echo "<p>$check</p>";
?>
It gives me the right division and the math is right on but, I still get a Warning: Division by zero in line 8 which is this line:
$payment = $total_amt * $monthly_int / (1 - pow(1+$monthly_int, $months )); //Determining Monthly Payment
When I print out the denominator by itself, it comes up with 0.8....... which is not 0...therefore how can I get a division by zero error? Thanks for the help in understanding this.
warmaster