Page 1 of 1
suppress errors
Posted: Mon Sep 27, 2004 3:39 pm
by nikko50
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:)
Posted: Mon Sep 27, 2004 3:43 pm
by Joe
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?.
Posted: Mon Sep 27, 2004 3:47 pm
by feyd
div by zero is usually bad to ignore, at any level. I'd make sure 'receivedsum' is correct and non-zero..
Posted: Mon Sep 27, 2004 3:57 pm
by nikko50
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?
Posted: Mon Sep 27, 2004 3:59 pm
by feyd
by not doing the math if it's zero received..
Posted: Mon Sep 27, 2004 4:01 pm
by nikko50
simple enough. Will do that.
Posted: Mon Sep 27, 2004 4:13 pm
by nikko50
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);
}
Posted: Mon Sep 27, 2004 4:18 pm
by Joe
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?.
Posted: Mon Sep 27, 2004 4:23 pm
by feyd
remember to always, always quote string array indices.
and please start using
Code: Select all
tags.
wouldn't the average actually be x / total ?
Posted: Mon Sep 27, 2004 4:26 pm
by nikko50
Hey Joe. Code works great. Thanks for all your help. If you can think of anything else let me know.
Tracy:)
Posted: Mon Sep 27, 2004 4:29 pm
by Joe
No problem.
