Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- Home
- >
- Acrobat SDK
- >
- Calculate x - y then if result is < 0, enter 0

Jan 19, 2019

Copy link to clipboard

Copied

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

Most Valuable Participant

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

TOPICS

Acrobat SDK and JavaScript

Community Guidelines

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

Jan 19, 2019

Copy link to clipboard

Copied

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

Most Valuable Participant

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

TOPICS

Acrobat SDK and JavaScript

Community Guidelines

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

jyoho107

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/td-p/10379456
8
Replies
8

Adobe Community Professional
,

Jan 19, 2019

Copy link to clipboard

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?

Community Guidelines

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

Reply

Loading...

gkaiseril

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379457#M15575
Jan 19, 2019

Copy link to clipboard

Copied

Will do - thanks

Judy

Community Guidelines

Reply

Loading...

jyoho107

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379458#M15576
Jan 19, 2019

Copy link to clipboard

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

Community Guidelines

Reply

Loading...

jyoho107

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379459#M15577
Most Valuable Participant
,

Jan 19, 2019

Copy link to clipboard

Copied

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

Community Guidelines

Reply

Loading...

try67

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379460#M15578
Jan 19, 2019

Copy link to clipboard

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

Community Guidelines

Reply

Loading...

jyoho107

Jan 19, 2019
1
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379461#M15579
Most Valuable Participant
,

Jan 19, 2019

Copy link to clipboard

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

Community Guidelines

Reply

Loading...

try67

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379462#M15580
Jan 19, 2019

Copy link to clipboard

Copied

It works! – am looking for the place to click ‘Correct’ -

Community Guidelines

Reply

Loading...

jyoho107

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379463#M15581
jyoho107
LATEST

Jan 19, 2019

Copy link to clipboard

Copied

The script works - thank you so much

Community Guidelines

Reply

Loading...

jyoho107

Jan 19, 2019
0
/t5/acrobat-sdk/calculate-x-y-then-if-result-is-lt-0-enter-0/m-p/10379464#M15582
Using the Community
Experience League
Terms of Use
Privacy Policy
Cookie preferences
AdChoices
Language:

- Deutsch
- English
- Español
- Français
- 日本語コミュニティ
- Português

Copyright © 2020 Adobe. All rights reserved.