Division by zero (1 Viewer)

libby32

Registered User.
Local time
Today, 10:52
Joined
Mar 6, 2003
Messages
42
Hi, sometimes a value will nedded to be divided into zero. When this happens, I need the answer to calculate to zero to be used in another calculation. Here is the code in the query that I am using to try to convert to 0 but it is not working...What have I done wrong??

LgQty: IIf((Nz([WtInLg])/Nz([No_Lg_Containers])*nz([LgfrWharf])=0,0, (Nz([WtInLg])/Nz([No_Lg_Containers])*Nz([LgfrWharf]))))
 

FoFa

Registered User.
Local time
Today, 04:52
Joined
Jan 29, 2003
Messages
3,672
You can't divide by zero.
You must check the value for zero, and return zero, else divide
 

Shadez

Registered User.
Local time
Today, 10:52
Joined
Jan 20, 2003
Messages
192
try somthing like this

=iif(nz(SomeField,0)=0,0,AField/SomeField)

This will check if somefield is 0 or empty if so return a 0 else do the calculation.

ie

IIf((Nz([WtInLg])/Nz([No_Lg_Containers])*nz([LgfrWharf])=0,0, (Nz([WtInLg])/Nz([No_Lg_Containers])*Nz([LgfrWharf]))))

Would be

iif(Nz([No_Lg_Containers],0)=0,0,Nz([WtInLg])/Nz([No_Lg_Containers])*Nz([LgfrWharf]))

this approch works


:cool:ShadeZ:cool:
 

Freddy

Abort, Retry or Ignore?
Local time
Today, 05:52
Joined
Jul 25, 2002
Messages
28
You have to test the denominator for zero. Then either pass a 0 for the full calculation.

Try this: LgQty: IIf(Nz([No_Lg_Containers])=0,0,(Nz([WtInLg])/Nz([No_Lg_Containers])*Nz([LgfrWharf]))))
 

Users who are viewing this thread

Top Bottom