PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nikko50
Forum Commoner
Posts: 43 Joined: Thu Apr 08, 2004 6:28 am
Post
by nikko50 » Mon Sep 27, 2004 3:39 pm
Hello. I'm getting warning division by zero messages with the below statement.
$average=$getcostline2[totalsum]/$getcostline[receivedsum];
Can I suppress these error messages with the @ control operator. If yes please show me how. Thanks so much.
Tracy:)
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Mon Sep 27, 2004 3:43 pm
Well it's either because your total values equal 0 or they are not running anything at all. What happens when you print out the variables?.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 27, 2004 3:47 pm
div by zero is usually bad to ignore, at any level. I'd make sure 'receivedsum' is correct and non-zero..
nikko50
Forum Commoner
Posts: 43 Joined: Thu Apr 08, 2004 6:28 am
Post
by nikko50 » Mon Sep 27, 2004 3:57 pm
Hi guys:) I'm pulling monthly inventory results so sometimes there will be no received sum along with no totalcost sum. How can I go about supressing those division by zero messages?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 27, 2004 3:59 pm
by not doing the math if it's zero received..
nikko50
Forum Commoner
Posts: 43 Joined: Thu Apr 08, 2004 6:28 am
Post
by nikko50 » Mon Sep 27, 2004 4:01 pm
simple enough. Will do that.
nikko50
Forum Commoner
Posts: 43 Joined: Thu Apr 08, 2004 6:28 am
Post
by nikko50 » Mon Sep 27, 2004 4:13 pm
Hey boys:)
Does this look good to you or how would you write it???
if($getcostline[receivedsum]=='0'){
$average='0';}
else{
$average=$getcostline2[totalsum]/$getcostline[receivedsum];
$average=round($average,2);
}
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Mon Sep 27, 2004 4:18 pm
I would probably use:
Code: Select all
if($getcostlineїreceivedsum] != 0)
{
$average=$getcostline2їtotalsum]/$getcostlineїreceivedsum];
$average=round($average,2);
}
What values did you get when you printed those variables to the screen?.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 27, 2004 4:23 pm
remember to always, always quote string array indices.
and please start using
Code: Select all
tags.
wouldn't the average actually be x / total ?
nikko50
Forum Commoner
Posts: 43 Joined: Thu Apr 08, 2004 6:28 am
Post
by nikko50 » Mon Sep 27, 2004 4:26 pm
Hey Joe. Code works great. Thanks for all your help. If you can think of anything else let me know.
Tracy:)
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Mon Sep 27, 2004 4:29 pm
No problem.