Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by Zero Error

Status
Not open for further replies.

fkelly72

Technical User
Feb 21, 2002
8
AE
I have a formula to calculate Margin as follows but gives a division by zero error on runtime.
({@ExtP}-{@Tot Cost})/{@ExtP}*100

I have tried using If <> 0 then 0 but still the same error.
 
What is the @ExtP formula?

Or try

If @ExtP > 0
then
({@ExtP}-{@Tot Cost})/{@ExtP}*100
else
({@ExtP}-{@Tot Cost})/100



[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Genius. I don't understand the formula but it works :) Thank you.
 
I don't understand the formula...

[tt]
If @ExtP > 0
then
({@ExtP}-{@Tot Cost})/{@ExtP}*100
else
({@ExtP}-{@Tot Cost})/100
[/tt]
[tt]
if @ExtP .is greater than. 0
then
perform the calculation
else[red]
@ExtP IS ZERO -- cannot use in denominator!!!
[/red]
perform some other calculation that does not divide by @ExtP
[/tt]
HOWEVER, this seems to me like a screwy formula to begin with. It seems UP SIDE DOWN!

You are taking the difference between a total cost and ExtP (not sure but is this Extended Price or some value that eventually becomes equal to total cost???) and dividing by a value that begins at ZERO and increases to..... what? total cost?

Making the assumption as just stated, I'd see as much more reaonable, the formula to be...
[tt]
({@ExtP}/{@Tot Cost})*100
[/tt]
and if you want the inverse of that then the formula would be...
[tt]
(1 - ({@ExtP}/{@Tot Cost}))*100
[/tt]


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Your assumptions are correct. I'm working out the margin % between Extended Price and Extended Cost on a sales table.
Sometimes the cost or the price may be zero and hense the error I was receiving.

the formula for margin % being (price-cost)/price*100
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top