Trying to avoid a divide by zero

  • Thread starter Justin Kerstetter
  • Start date
J

Justin Kerstetter

I'm sending price and quantity values to a mail merge doc,
and would like to calculate a "price per each" field. The
Price/Qty formula works great when a quantity exists, but
the problem is that there are cases when the quantity (and
the price, for that matter) are equal to zero.
I've wrestled with the "if" statement shown below, but I'm
still getting the 'divide by zero' error when the merge is
run. I'm thinking the division formula is being evaluated
regardless of its place in the "if" statement. Any
suggestions on how to get the field to do the division if
the quantity is not zero, but to get it to suppress or
print "0.0000" when the quantity is zero?

Here's the statement I've been working with:
{ IF Qty2 <> 0 {=Price2/Qty2 \# "#,###,##0.0000"} 0.0000 }

Much thanks in advance,

Justin
 
G

Greg Maxey

Justin,

Thanks for the challenge. This one had me stumped for awhile. I tested
using tables cells so I hope this will work with your merge fields. Try:

{IF {=b1} = 0 {=0 \# "''" } {=a1\b1}

Where a1 represents your Price2 mergefield, b1 represents your Qty2
mergefield and the bit following tyeh \# is a double quote, two singel
quotes, and a double qoute.

HTH
 
G

Greg Maxey

I made this harder than necessary. An IF field (now tested in a merge)
formatted as follows will work:

{ ID { = {MergeField Price2}/{MergeField Qty2}} = "!Zero Divide" "" { =
{MergeField Price2}/{MergeField Qty2}}}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top