Skip to main content
Participating Frequently
September 10, 2021
Answered

Math Calculation Help

  • September 10, 2021
  • 1 reply
  • 865 views

Hello,

 

I've been having trouble making certain calculations work. I was working on this form a few months ago, and thought this particular calculation was working, but it's not now, and I can't figure out what's wrong with it. When I compare it to other fields with similar expressions that do work, I can't see the difference. Perhaps "new eyes" will help.

 

var f = Math.ceil(this.getField("1 - Total Output Current" + "2 - Total Output Current" + "3 - Total Output Current").value / 5) * 5;

event.value = util.printf("%.0f", f);

Correct answer Nesa Nurani

Try it like this:

var a = Number(this.getField("1 - Total Output Current").valueAsString);
var b = Number(this.getField("2 - Total Output Current").valueAsString);
var c = Number(this.getField("3 - Total Output Current").valueAsString);
var x = Math.ceil((a+b+c)/5)*5;
event.value = util.printf("%.0f", x);

 

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 10, 2021

Try it like this:

var a = Number(this.getField("1 - Total Output Current").valueAsString);
var b = Number(this.getField("2 - Total Output Current").valueAsString);
var c = Number(this.getField("3 - Total Output Current").valueAsString);
var x = Math.ceil((a+b+c)/5)*5;
event.value = util.printf("%.0f", x);

 

Participating Frequently
September 10, 2021

That worked perfect! I think I got the original script from try67, and he seems to create extremely succinct scripts. Was there anything wrong with what I had, or is Acrobat just finicky?

Bernd Alheit
Community Expert
Community Expert
September 10, 2021

Following is wrong:

this.getField("1 - Total Output Current" + "2 - Total Output Current" + "3 - Total Output Current").value

 

You must use getField for every field.