LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Divide by Zero, LAE 6.1

    Employee
    Posted 01-14-2016 17:29

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ahines

    Hello, All- back again. So, I am taking a dive into the creation of largescale KPI reports and my first run into doing mathematic calculations in LAE. Of course, I very quickly came across divide by zero errors. After some quick searching I found the following article with instructors on an older version and attempted them to know avail:

    http://community.lavastorm.com/archi...hp/t-3072.html

    I thought that conditional logic would solve the problem, much the same way it does in my excel versions of the same reports...

    If ('Customer Count'.int()==0) or ('Sales'.double() ==0)
    then AverageTicket.double()=0 
    else AverageTicket= ('sales'.double() / 'customer count'.int())
    emit AverageTicket.double()
    Unfortunately when I attempt to do it this way I get "unexpected token (then) at line 3. The last 2 lines of the code, sans the [I]else[I] give me the divide by zero. How are people handling this issue now?


  • 2.  RE: Divide by Zero, LAE 6.1

    Employee
    Posted 01-14-2016 18:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    You've found a very odd bug in the parser. It should have thrown a (better) error message.
    The "I" on the "if" operator should be lower case. Make it "if" and the error goes away.

    However, you've also got another issue... in two places you're using "double" function incorrectly.
    You also do not need to test the numerator, only the denominator of the divide.
    Here is the corrected version:

    if ('Customer Count'.int()==0)
    then AverageTicket = double(0)
    else AverageTicket= ('sales'.double() / 'customer count'.int())
    emit AverageTicket
    =======
    Now, to get all technical.. if you do need to test a "double" data type, then (abs(Sales.double()) < 0.000001)
    is a better than the ('Sales'.double() ==0) you were using.
    Because of floating point rounding errors, it's best to use "less than" some very small number rather than "equality".


  • 3.  RE: Divide by Zero, LAE 6.1

    Employee
    Posted 01-15-2016 10:44

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ahines

    Thanks for the reply, Stony- I understand the syntax error on the if (and I'm feeling a bit dumb because of it), but not what you were talking about with the Double(). Admittedly, I think I was spitballing with that, as I was attempting to move it into a data type for decimal points and everything I've read for math calculations said that LAE wasn't fond of them and used the double test with them. Since I hadn't gotten this to work in order to test, I believe I was just trying to cover all my bases. Let me test this out and I'll get back to you. Hopefully this will solve all the issues, as I have about 9 other new expressions to create following this same principal.