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.  How to reduce a counter value when certain conditions are met?

    Employee
    Posted 03-03-2010 22:26

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

    Originally posted by: JimmyT

    Hi,

    I'm interested to reduce a counter value (in the case below, field BalCredits) when certain conditions are met.

    For example, there are 4 fields in total. Name, Charge, StartCredits, BalCredits.

    Under field Name, there is only two types of values, Adam and Eve.
    Under field Charge, there are 2 different charges, $0.20 (when field BalCredit = 0) and $0.00 (when field BalCredit > 0)
    Under field StartCredits, $1.00, for each respective person i.e. Adam / Eve
    Under BalCredits, value ranges from $1.00 to $0.00 for each Adam and Eve, a deduction of $0.20 for every record by Adam or Eve

    For the above scenario, I used an agg node (on field Name) with the following script, but doesn't seem to work. The result of the following script outputs the value of BalCredits in the following order. $1.00, $0.80, $0.60, $0.40,$0.20, 5.55111512313e-017, -$0.20, $0.00


    if firstInGroup then BalCredits = StartCredits

    if BalCredits > 0 then BalCredits = BalCredits - 'Charge'

    emit *,
    BalCredits as "BalCredits"



    All advice welcome!,
    Jim
    Attachments:
    Discount Counter.zip


  • 2.  RE: How to reduce a counter value when certain conditions are met?

    Employee
    Posted 03-04-2010 09:53

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

    Originally posted by: rboccuzzi

    I am not sure what your question is, or what isn't working right.

    I suspect though, it is the 5.55...e-017? And the fact that the next value in line goes negative, and then goes to zero after? If that is your problem, then what you are seeing is the nature of floating point math; not just in our software, but in general.

    It is talked about in the BRAINscript help to some extent, under General Language Elements, the section Floating Point Arithmetic. Here, you are seeing a number that is close to but not precisely 0.

    If I understand what you want, I think you would just change your compare in your graph from
    if Discount_Bal > 0 then
    to
    if Discount_Bal > 0.001 then
    where .001 is your epsilon, your tolerance for what is "close enough" to zero to mean zero; adjust to meet your needs.

    Cheers
    Rich


  • 3.  RE: How to reduce a counter value when certain conditions are met?

    Employee
    Posted 03-04-2010 15:59

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

    Originally posted by: JimmyT

    thanks that solved my problem.