Highlighted

Acrobat formula if number is 0 then dont calculate

New Here ,
Oct 16, 2020

Copy link to clipboard

Copied

Its been a while since i have been into Java. I want to calculate a percentage but if the first number is zero then dont calculate.  This is what I have so far:

 

var a=this.getField("CT-TPE");
var b=this.getField("CT-TPV");
var c=this.getField("PER.0.0");
c.value=(a.value/b.value);

 

Any help would be so appreciated.

 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this code, instead:

 

var a = Number(this.getField("CT-TPE").valueAsString);
var b = Number(this.getField("CT-TPV").valueAsString);
if (b==0) event.value = "";
else event.value=a/b;
TOPICS
PDF forms

Views

43

Likes

Translate

Translate

Report

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

Acrobat formula if number is 0 then dont calculate

New Here ,
Oct 16, 2020

Copy link to clipboard

Copied

Its been a while since i have been into Java. I want to calculate a percentage but if the first number is zero then dont calculate.  This is what I have so far:

 

var a=this.getField("CT-TPE");
var b=this.getField("CT-TPV");
var c=this.getField("PER.0.0");
c.value=(a.value/b.value);

 

Any help would be so appreciated.

 

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Use this code, instead:

 

var a = Number(this.getField("CT-TPE").valueAsString);
var b = Number(this.getField("CT-TPV").valueAsString);
if (b==0) event.value = "";
else event.value=a/b;
TOPICS
PDF forms

Views

44

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 16, 2020 0
Contributor ,
Oct 16, 2020

Copy link to clipboard

Copied

You can't divide with zero. Also it's javascript not java. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2020 0
New Here ,
Oct 16, 2020

Copy link to clipboard

Copied

Thank you for the clarification. The form will have a zero at times, so how do i create a formula that says if it a zero then ignore?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2020 0
New Here ,
Oct 16, 2020

Copy link to clipboard

Copied

Do you know how i could do it if null?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2020 0
Most Valuable Participant ,
Oct 16, 2020

Copy link to clipboard

Copied

Use this code, instead:

 

var a = Number(this.getField("CT-TPE").valueAsString);
var b = Number(this.getField("CT-TPV").valueAsString);
if (b==0) event.value = "";
else event.value=a/b;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 16, 2020 0
New Here ,
Oct 17, 2020

Copy link to clipboard

Copied

That did it.  Thank you so much!!!

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 17, 2020 0