• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Acrobat formula if number is 0 then dont calculate

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

 

TOPICS
PDF forms

Views

344

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
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 16, 2020 Oct 16, 2020

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;

Votes

Translate

Translate
Enthusiast ,
Oct 16, 2020 Oct 16, 2020

Copy link to clipboard

Copied

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

Votes

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

Votes

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

Copy link to clipboard

Copied

Do you know how i could do it if null?

Votes

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
community guidelines
Community Expert ,
Oct 16, 2020 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;

Votes

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

Copy link to clipboard

Copied

LATEST

That did it.  Thank you so much!!!

 

Votes

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
community guidelines