Division by zero

libby32

Registered User.
Local time
Today, 21:31
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]))))
 
You can't divide by zero.
You must check the value for zero, and return zero, else divide
 
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:
 
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

Back
Top Bottom