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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula error: Division by zero

Status
Not open for further replies.

LSQUARE

Technical User
Aug 22, 2003
15
CA
I'm writing a gross profit % formula. Basically Sales less costs / Costs = GP%

Eg. Sales = 100, Costs = 75, GP = 25

(100 less 75) / 75 = 33%

The formula works great in the above situation whereby the GP is not equal to 0. However, my formula does not work in scenarios whereby the GP is = 0. This is where Crystal generates the "Divison by zero" error message

Here's what the CR formula looks like:

If {@Total Sale} <> 0.00 Then (({@Total Sale} - {WOITEMS.TOTALCOST}) / {WOITEMS.TOTALCOST}) * 100
Else 100.00

I'd like to know a way to resolve this. Any suggestions are much appreciated.
 
I think you are misreading the message.
The message is telling you that you have a zero value for:
{WOITEMS.TOTALCOST}

At the moment, your formula will report 100 if the total SALES is zero, otherwise it tries to do the GP% calculation.
So, if the total sales is not zero but the total cost is zero then you will get the error message.

What result do you want to report in this situation?

 
As lupins46 says, you need an extra test. Something like
Code:
if {WOITEMS.TOTALCOST}) = 0 
then 0
else If {@Total Sale} <> 0
Then (({@Total Sale} - {WOITEMS.TOTALCOST}) /{WOITEMS.TOTALCOST}) * 100
Else 100

There is no need to say 0.00 or 100.00, since these values are assumed.

It helps to give your Crystal version, since newer versions have extra solutions, and some extra problems. I use Crystal 8.5

Madawc Williams (East Anglia)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top