Skip to main content
Participating Frequently
February 6, 2023
Answered

Dividing 0's

  • February 6, 2023
  • 1 reply
  • 590 views

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.

 

Thank you in advance

This topic has been closed for replies.
Correct answer try67

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

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 7, 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 event.value = v1/(v2*100);

 

Participating Frequently
February 8, 2023

try67...THIS WORKS PERFECTLY!!!

Thank you sooo very much!!

Fred