8 Replies Latest reply on Apr 29, 2014 8:25 PM by Trendyfroggy

# Problem with substraction with a negative number

Hello,

I wonder if someone could help me figure out how to script a calculation properly...

I have field A   -  B   -  C  -  D -  E

A = Expected Revenue

B = Previous Withdrawals

C = Fixed Annual Index = \$26250

D = 66.6% of (A-B)

E = C - D

I am trying to find the right script so that it would substract correctly when D is a negative number.

Somehow E result indicates a negative number when it should in fact be a positive one and I'm not too sure why...

In practice, it come to 26250 - (-D) which should therefore be 26250 + D but I always get a negative value for E???

I am practicing on a Canadian Government Form for fanancial harship that is at http://www.osfi-bsif.gc.ca/Eng/Docs/form1.doc

50% of the Year’s Maximum Pensionable

Earnings as defined in the Pension Benefits Standards Act, 1985 is \$26250.

Any help would be greatly appreciated ;-)

Thanks

• ###### 1. Re: Problem with substraction with a negative number

Can you share the file you're working on?

• ###### 2. Re: Problem with substraction with a negative number

Hello Trendy:

Have you tried something like this (this is from off the top of my head so you might have to make a few adjustments):

if(C < D)

abs(D) - abs (C);

else

abs(C) - abs(D);

I know this is a bit of smoke and mirrors, but something like this should work if the idea is to force E to a positive value.  And btw, the abs function needs to come from the math object, I think.

Good luck.

John

• ###### 3. Re: Problem with substraction with a negative number

It appears there is more to calculations for the "D: seires of fields:

D Low Income Withdrawal component.

\$________

Enter amount from D(1v) if greater than

zero otherwise enter “0”

D(i) A - B \$________

D(ii) 66.6% of D(i) \$________

D(iii) C - D(ii) \$________

D(iv) D(iii) - B(i) \$_______

• ###### 4. Re: Problem with substraction with a negative number

Thanks for the additional information.  I'm not sure my advice applies at all any more.

• ###### 5. Re: Problem with substraction with a negative number

Yes there is indeed...

This I managed to overcome by including :

var z = this.getField("D4").value;

if (z > 0) {

event.value = 0;

} else {

event.value = this.getField("D4").value;

}

This seems to be working well ;-)

• ###### 6. Re: Problem with substraction with a negative number

Hi Gilad D,

Yeah how do I go about this sharing this file on here?

Sorry I'm rather a newbie on this community.

I have a PDF file ready...

• ###### 7. Re: Problem with substraction with a negative number

No problem JADarnell,

Gosh why do they make these government forms so complicated??? lol

• ###### 8. Re: Problem with substraction with a negative number

So I managed to advance. The calculation seems to be working well so far. I added in Bold the calculations entered in the Field Properties. The only thing that is blocking me now is the A value. A has to be equal or greater than B as B is automatically considered as revenue and is therefore included in A.

I tried a little trick by simply defining the value of A as the MINIMUM and I just selected B in the choices which seems to work meaning that when you change something in B1 or B2, it automatically changes the general value of B and therefore the A value picks up too that minimum value but the problem is that the rest of the calculations undeneath do not work anymore....

Any suggestions???

 A Expected income in this calendar yeardetermined in accordance with theIncome Tax Act. \$ ________ B Total financial hardship withdrawals madeduring the calendar year from allfederally-regulated locked-in registeredretirement savings plans, life income funds, restricted life income funds and restrictedlocked-in savings plans. \$ ________ B1 + B2 B(i): total low income component of B is \$ ________ B(ii): total medical and disability-related income component of B is \$ ________ C 50% of the Year’s Maximum PensionableEarnings as defined in the Pension Benefits Standards Act, 1985. \$ ________

 Calculation Of Low Income Component Of Withdrawal(To be completed only if seeking withdrawal under this component) D Low Income Withdrawal component. \$________ var z = this.getField("D4").value;  if (z <= 0) {event.value = 0;} else {event.value = this.getField("D4").value;} Enter amount from D(1v) if greater than zero otherwise enter “0” D(i) A - B \$________ A - B D(ii) 66.6% of D(i) \$________ D1 * 0.666 D(iii) C - D(ii) \$________ C - D2 D(iv) D(iii) - B(i) \$________ D3 - B1