Skip to main content
Participating Frequently
January 19, 2019
Answered

Calculate x - y then if result is < 0, enter 0

  • January 19, 2019
  • 2 replies
  • 1041 views

Calculate x - y then if result is < 0, enter 0

This topic has been closed for replies.
Correct answer try67

Line 7 of the Local Tax Form says:

7. Total Taxable Net Profit (Subtract Line 6 from Line 5. If less than zero, enter zero) .

.

I did the subtraction -

NetProfit - NetLoss

But don't know how to set the result (TotalTaxNP) to 0 if it is < 0

if NetLoss > NetProfit, then TotalTaxNP = 0


Use this code as the custom calculation script of your field:

var v1 = Number(this.getField("NetProfit").valueAsString);

var v2 = Number(this.getField("NetLoss").valueAsString);

event.value = Math.max(0, v1-v2);

2 replies

jyoho107Author
Participating Frequently
January 19, 2019

The script works - thank you so much

Inspiring
January 19, 2019

I would start by searching the forums.

This action will require a custom JavaScript so the exact field names will be required.

Have you considered using the Math.max method?

jyoho107Author
Participating Frequently
January 19, 2019

Will do - thanks

Judy