BIRT Exchange Forum: divide by zero error - BIRT Exchange Forum

Jump to content


 

No Latest Open Poll.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

divide by zero error Rate Topic: -----

#1 User is offline   mariaD Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 12
  • Joined: 17-October 08


Posted 02 February 2012 - 01:46 PM

Hello,

I have a simple calculated field, which is one column divided by another. If the denominator is 0, I get the error 'Divide By Zero Error'. I would like to handle that case within the calculated field if possible ( instead of the SQL or the Data Range), but I am not sure how to write the expression, so that the code will compile and return just 0.

I tried using the ISERROR function, but that doesn't seem to work.

Any suggestions how I should do this?

here's my calculated field:

GROSS_SALES_CNT / TOTAL_CONTACT_CNT
0

#2 User is offline   sooryanidh Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 23-January 12


Posted 02 February 2012 - 11:06 PM

There is a BirtMath function of safeDivide. Just use that function. It takes 3 parameters... divisor, dividend, custom value

something like...
BirtMath.safeDivide(GROSS_SALES_CNT, TOTAL_CONTACT_CNT,0.0) in the exrepssion field of calculated value.
0

#3 User is offline   bgbaird Icon

  • Senior Member
  • Group: Members
  • Posts: 114
  • Joined: 25-February 10


Posted 03 February 2012 - 05:31 AM

You can also do the division inside an if/else.

if (Divisor==0)
{0;}
else
{Dividend/Divisor;}


Brian
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users