Highlighted

## Acrobat formula if number is 0 then dont calculate

New Here ,
Oct 16, 2020

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
| Most Valuable Participant

``````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

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

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
| Most Valuable Participant

``````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

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
5 Replies 5
Contributor ,
Oct 16, 2020

Copied

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

Likes

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
New Here ,
Oct 16, 2020

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

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
New Here ,
Oct 16, 2020

Copied

Do you know how i could do it if null?

Likes

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
Most Valuable Participant ,
Oct 16, 2020

Copied

``````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

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
LATEST
New Here ,
Oct 17, 2020

Copied

That did it.  Thank you so much!!!

Likes

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 17, 2020 0
Resources