Skip to main content
1-Visitor
May 16, 2014
Solved

Computed Expression help

  • May 16, 2014
  • 2 replies
  • 2462 views

We are using MKS Integrity 2009 SP5. Yes, I know we need to upgrade, but we are under-staffed.

I am trying to make a calculation (Computed expression Integer type field) work. When I try to edit an item I get an error "Division by zero has been detected processing the query on the server". I understand the error. I don't know how I can resolve it. What I am doing is dividing 2 integer fields to return a percentage. Example: field3 (Integer) computed expression: "field1" / "field2". These 2 fields are divided to give a percentage.

If field1 = 10 and field2 = 100 then field3 should display 10%.

However, if field1 and/or field2 has zero (default) then the division error is displayed. I understand you cannot divide a number by zero.

If field1 = 0 and field2 = 100 then field3 should display 0%.

How can I get it to simply calculate or say 0%, because that is what it should be?

Thank you,

Capture.JPG

    Best answer by mrump

    Hi Daniel,

    1. IMHO the field type of your computed "Field3" should be "floating point".

    2. IMHO the computaion should be:

    isEmpty( ("field1") / ("field2" + 0.001),0.)

    HTH Matthias

    2 replies

    mrump16-PearlAnswer
    16-Pearl
    May 16, 2014

    Hi Daniel,

    1. IMHO the field type of your computed "Field3" should be "floating point".

    2. IMHO the computaion should be:

    isEmpty( ("field1") / ("field2" + 0.001),0.)

    HTH Matthias

    DanR.1-VisitorAuthor
    1-Visitor
    May 16, 2014

    Is it safe to assume that I cannot mix apples and oranges. So all those fields should be floating point. Correct?

    16-Pearl
    May 19, 2014

    As far as I know, the resulting field Type is the driver.

    So, as long as you are calculyting a floating point field, the calculation may still contain integer values.

    At least in the field definitions of the PTC ALM Solution this is used several times.

    1-Visitor
    May 19, 2014

    All correct. The only one that _has_ to be float is the final computation. Others can be or not. Where integers are divided and nested, I've also had to multiply the ratio by 1.0 to prevent the result from being rounded to integer before the next operator is applied. THAT trick is the least obvious. When in doubt, try it.