PDA

View Full Version : Avoid Warnings on F2S?? (divide by zero)



Magic2K2
July 23rd, 2001, 20:10
I need to be able to divide by zero on my website, but I cannot do so right now without receiving the warning from F2S. I don't want to have to add checks throughout all my scripts to determine if it's dividing by zero beforehand and make the appropriate changes. Is there any way around this?

bigperm
July 23rd, 2001, 20:25
Umm... you can't divide by zero.

lucifer
July 23rd, 2001, 20:41
what's stopping you. dividing by zero is fun! :cool:

use java and catch those exceptions


I'm sure you can put in a tiny bit of variable checking (like you should anyway - you did check it was a number? :eek: )

fatman
July 23rd, 2001, 23:07
Originally posted by Magic2K2
I need to be able to divide by zero on my website, but I cannot do so right now without receiving the warning from F2S.

Just curious - why would you want to divide by zero?

Magic2K2
July 24th, 2001, 07:44
It's a basketball site and I need to compute statistical averages for players. If a player has yet to play a game, his points per game is calculated by: points / gms = 0 / 0

I think I will use the JavaScript.

lucifer
July 24th, 2001, 07:50
Originally posted by Magic2K2
I think I will use the JavaScript.

you'd be better off with as server side script. So it'd work for all your visiters

just use a line like

$ppg = ($games==0) ? 0 : $points/$games;

Magic2K2
July 24th, 2001, 08:20
THANK YOU LUCIFER!!

Now, that code will work in PHP right?

lucifer
July 24th, 2001, 08:40
yip


or use

if ($games==0) {
$ppg=0;
} else {
$ppg= $points/$games;
}

if you want something easier to read

LastActionHero
July 24th, 2001, 09:26
Originally posted by lucifer

you'd be better off with as server side script. So it'd work for all your visiters

just use a line like

$ppg = ($games==0) ? 0 : $points/$games;

more refined

$ppg = (!$games) ? 0: $points/$games;

or

$ppg = ($games) ? $points/$games:0

;) :)

niv
July 24th, 2001, 09:52
if (!$games) $ppg = 0; :p