Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculate with negative prefix

New Here ,
Aug 27, 2009 Aug 27, 2009

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.

1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 27, 2009 Aug 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 29, 2009 Aug 29, 2009
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources