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.  Filter on a double

    Employee
    Posted 05-31-2014 14:28

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

    Originally posted by: SambaDancer

    Dear all,

    Using Lavastorm 5

    Field "myValue" of type "double" shows a value of 194.89
    I want to filter on this exact value.
    However, if I make a filter node (from the BRD Viewer: Copy as filter) where it says emit * where myValue == 194.89 gets 0 results.
    Only emit * where myValue.str() == "194.89" gets me the exact number of results.

    I guess this has something to with rounding and scientific notation.
    But even the following code gets me 0 results:

    test = (myValue * 100).int()/100
    emit *,test where test = 194.89

    Can someone please explain - in lay-man's terms - why this is so difficult and what I could do to ease things?

    Thanks!
    Bart Roeleveld (Coney, The Netherlands).


  • 2.  RE: Filter on a double

    Employee
    Posted 06-02-2014 04:26

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

    Originally posted by: Tim Meagher

    Hey,

    The "double" field is stored as a floating point value so this is the problem here.
    There's a reasonably good description of this "Fixed Point Arithmetic" section of the BRAINscript help.
    In addition, the following forum thread might have some additional info to help you: http://community.lavastorm.com/threa...unding-nearest

    By converting to an integer you should be working around the problem somewhat, however, you've then converted *back* to a double type, where the floating point arithmetic problem will be present again.

    You should probably either do the calculation using integer math, or use some sort of tolerance to determine if the value is close enough to what you are expecting, like:

    closeEnough = abs(myValue-194.89) < 0.0001
    emit * where closeEnough
    Regards,
    Tim.


  • 3.  RE: Filter on a double

    Employee
    Posted 06-02-2014 08:56

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

    Originally posted by: SambaDancer

    Hi Tim, thanks for explaining.
    I already read that part of the help file, it was pretty good, although fairly technical.
    The thing is, my target group consists of auditors who willhave real trouble understanding stuff like that (they're more at the Excel level ;-)
    I think maybe I should request a change for this?
    thanks again and best greetings from The Netherlands!
    Bart.