Expand my Community achievements bar.

SOLVED

ES3 - Calculation = neg number and want it to be 0 or greater

Avatar

Level 2

I have a 2 fields, one is an estimate and one is the actual cost. We are trying to calculate if there was an increase between the actual cost and the estimate. We estimate high so that our actual cost never goes above the estimate. Thus Actual - Estimate = negative number (meaning that the actual cost was not higher than the estimate). We have to show this number as either $0.00 (indicating that there was not an increase) or a higher dollar amount showing that the actual cost was higher than the estimate.

What I am trying to do when I subtract Actual - Estimate and it comes to a negative number, that it actually will only show up as $0.00 (if negative) or greater.

Then the second part is I have to show this "increase" as a percentage. So it would be Actual/Estimate.

Example

          Estimated: $350.00    Actual   $360.00

                

                   (360-350)           (360/350)

Difference:    $10.00      or       2.85%

          Estimated: $350.00    Actual: $275.00

Difference: $-75.00      or        0%

( I want this part to show $0.00      or     0% )

Thanks for your help!

1 Accepted Solution

Avatar

Correct answer by
Level 2

To calculate the difference make use of:

var diff= (Actual.rawValue - Estimate.rawValue);

if(diff < 0)

{

this.rawValue=0;

}

else

{

this.rawValue=diff;

}

To calculate the percentage difference you could make use of:

var diffPer= (Actual.rawValue/ Estimate.rawValue);

if(diffPer < 1)

{

this.rawValue=0;

}

else

{

this.rawValue=diffPer;

}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

To calculate the difference make use of:

var diff= (Actual.rawValue - Estimate.rawValue);

if(diff < 0)

{

this.rawValue=0;

}

else

{

this.rawValue=diff;

}

To calculate the percentage difference you could make use of:

var diffPer= (Actual.rawValue/ Estimate.rawValue);

if(diffPer < 1)

{

this.rawValue=0;

}

else

{

this.rawValue=diffPer;

}

Avatar

Level 2

I was able to get the percent side to work, however the 0$ side did not work. I went over it a few times.. Is there another way I could calculate the diff variable??