cancel
Showing results for 
Search instead for 
Did you mean: 

how to handle division by zero error in sap crystal report custom formula function

Former Member
0 Kudos

Hi,

I have one report in that there is one custom function created called percentage when i run the report it give me error like division by zero. here is that function

Function (stringvar amount11,stringvar amount22)

stringvar amount1 := replace(replace(amount11,'.',''),',','');

stringvar amount2 := replace(replace(amount22,'.',''),',','');

if length(amount2) < 16 then

(

tonumber(amount1)*100/tonumber(amount2)

)

else

(

numbervar c:= length(amount2) - 15;

if length(amount1) > c then

(

stringvar amount3 := left(amount1,length(amount1)-c) + '.' + replace(replace(right(amount1,c),'.',''),',','');

tonumber(amount3)*100 /tonumber(left(amount2,15))

)

else

(

0

)

)

in RED highlighted area here i got that error. how i can resolve this one.

Kind Regards,

Ganesh

Accepted Solutions (0)

Answers (1)

Answers (1)

abhilash_kumar
Active Contributor
0 Kudos

Hi Ganesh,

Change the formula in which the function is being called to:

stringvar amount22;

if amount22 = 0 then 0 else

Function (stringvar amount11,stringvar amount22);


-Abhilash

Former Member
0 Kudos

Hi Abhilash,

i follow as u told but i dosent got the correct output it shows all values to zero but there is some value is not zero then it also shows zero.

abhilash_kumar
Active Contributor
0 Kudos

If you don't see the error anymore, then it is clear that the issue is with the custom function you've written.

If you want someone to help you with the logic for the function, please post that as a new discussion with detailed description on what you want the function to do.

-Abhilash