Skip to main content
Participant
August 27, 2009
Question

Calculate with negative prefix

  • August 27, 2009
  • 1 reply
  • 1572 views

Hi,

I'm seeing code like this.

<cfset variables.AltTotalPrice = -(-Val(Order.TotalPrice) - Val(variables.TotalAltAmountRemaining))>

What does "(-Val(Order.TotalPrice)" do?

I created a simple test and it seems it is just returning negative values.

Can someone shed light why does a previous developer doing this?

Thanks.

    This topic has been closed for replies.

    1 reply

    matt_xtrAuthor
    Participant
    August 27, 2009

    this one adds up totalprice and totalaltamountremaining that it doesn't seem to subtract base on the cfset below.

    <cfset TotalPrice = 90 />
    <cfset TotalAltAmountRemaining = 80 />

    <cfset t = TotalPrice - -Val(TotalAltAmountRemaining)>
    <cfdump var="#t#">

    strange formula that I can't answer why this adds up. any idea?

    Participating Frequently
    August 29, 2009

    matt_xtr,

    it is simple math really. think of :

    TotalPrice - -Val(TotalAltAmountRemaining)

    as :

    90 - (-80)

    I can't really speak to why the developer wrote it that way.