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

Dividing 0's

New Here ,
Feb 06, 2023 Feb 06, 2023

Copied

I have 2 calculated fields [txtMM] and [CalcEATotal] that supply another calculated field [AVGTotal413] with their values from 0  to 10.

AVGTotal413 has a Simplified field notation of "txtMM/CalcEATotal*100" but I MUST ensure that  it wont calculate if either [txtMM] and [CalcEATotal] are equal to 0. If either is a zero, acrobat will throw an error no matter what page in the document you are on.

While my VBA logic could probably solve this issue, my knowledge of Javascript is in it's infancy and I need help here.

TOPICS
Acrobat SDK and JavaScript

Views

387

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 , Feb 07, 2023 Feb 07, 2023

That's not quite true. If the numerator is 0 the result will be zero. Only if the denominator is zero will that result in an invalid operation, the result of which (in JS) is Infinity, but that can't be displayed by a field with the Number format, hence the error.

To solve it you must use a script to check the value of the latter first, like this:

``````var v1 = Number(this.getField("txtMM").valueAsString);
var v2 = Number(this.getField("CalcEATotal").valueAsString);
if (v2==0) event.value = "";
else ``````
...

2 Replies 2
Community Expert ,
Feb 07, 2023 Feb 07, 2023

Copied

That's not quite true. If the numerator is 0 the result will be zero. Only if the denominator is zero will that result in an invalid operation, the result of which (in JS) is Infinity, but that can't be displayed by a field with the Number format, hence the error.

To solve it you must use a script to check the value of the latter first, like this:

``````var v1 = Number(this.getField("txtMM").valueAsString);
var v2 = Number(this.getField("CalcEATotal").valueAsString);
if (v2==0) event.value = "";
else event.value = v1/(v2*100);``````

Report

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

Copied

LATEST

try67...THIS WORKS PERFECTLY!!!

Thank you sooo very much!!

Fred