...

View Full Version : Division by Zero Using Floating point. Why?



dealmaker
07-11-2007, 05:38 PM
Hi all,
my code has the following equation and the number was gotton from the mysql database:

$num = - 5.5813651706861/ 1.8673620948785

But somehow I got the following errors:

Warning: Division by zero in /home/mysite/public_html/myfile.php on line 564

Do you know why?
Thanks.

Fumigator
07-11-2007, 05:59 PM
Something tells me the actual code you are running ends up with a zero in the denominator.

dealmaker
07-11-2007, 06:47 PM
No, I echo the variables and the numbers I included in the original post is the value of the variables. It's not 0. It's a really long floating number.


Something tells me the actual code you are running ends up with a zero in the denominator.

Fumigator
07-11-2007, 07:17 PM
You can prevent the error with an "if" statement.

Also try casting the variables to float type.


if ((float) $b == 0) {
echo "Attempt to divide by 0.";
//handle the situation
} else {
$v = (float) $a / (float) $b;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum