• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Re: Calculate x - y then if result is < 0, enter 0

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

Community Beginner ,
Jan 19, 2019 Jan 19, 2019

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

619

Report

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

Community Expert , Jan 19, 2019 Jan 19, 2019

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);

8 Replies 8
LEGEND ,
Jan 19, 2019 Jan 19, 2019

Copied

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?

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jan 19, 2019 Jan 19, 2019

Copied

Will do - thanks

Judy

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jan 19, 2019 Jan 19, 2019

Copied

This a a calculation

for a local tax form ( I work

with AARP)

I can do the subtraction -

But then if the amount is

less than 0 - they must enter 0

on the form.

Iâ€™ve searched the forums and

tried a few things they showed -

Still having problem - but will keep

trying

Thanks again

Judy

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 19, 2019 Jan 19, 2019

Copied

If you post the actual field names we can help you with the code...

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jan 19, 2019 Jan 19, 2019

Copied

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

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
Jan 19, 2019 Jan 19, 2019

Copied

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);

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jan 19, 2019 Jan 19, 2019

Copied

It works! â€“ am looking for the place to click â€˜Correctâ€™ -

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Jan 19, 2019 Jan 19, 2019

Copied

LATEST

The script works - thank you so much