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

Reg:Division by zero error

Status
Not open for further replies.

malam123

Programmer
May 23, 2006
13
US
Hi
I have a Report which runs on date parameter and it works fine when we refresh it,when we try to export it or go to last page it gives division by zero error.I tried with checking the option of convert database default values to null and default in Report Options along with that I changed that particular formula in this way

If
(
IsNull({Table1.field_1}) or {Table1.field_1}=0
)
Or
(
IsNull({Table1.field_2}) or {Table1.field_2}=0
)
Then
0
Else
{@formula_x}/{Table1.field_2}/{Table1.field_1}

//these fields are number fields
Is there any way we can modify the code so that It does not affect the other values of the Report
 
I've made the experience that isNull sometimes does not work if it is not the first statement in the formula. Therefor I would do the following.

Formula_field_1:
if IsNull({Table1.field_1})
then
0
else
{Table1.field_1}

Formula_field_2:
if IsNull({Table1.field_2})
then
0
else
{Table1.field_2}

In the existing formula you described above:
if {@formula_field_1} = 0
or {@formula_field_2} = 0
then
0
else
{@formula_x}/{Table1.field_2}/{Table1.field_1}




Barbara Fuhrmann (Cologne, Germany) - Using Windows 2000/XP, Oracle 9i and Crystal Reports X
 
Interestingly, you can divide by NULL but you can't divide by zero.

NULL in many calculations creates a NULL result, while mathematically, you are just not allowed to divide by zero. The Algebra gods just say you can't do it and there is an algebra proof to support that.

Just be careful with the multiple divides in your formula.
It will do them in sequence.
{field1}/{field2}/{field3}
You might get the same result with
{field1}/({field2} * {field3})

So modify your formula to read
if {field2}=0 or {field3}= 0 then 0 else
{field1}/{field2}/{field3}

Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top