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

Math Calculation Help

Community Beginner ,
Sep 10, 2021 Sep 10, 2021

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

TOPICS
Create PDFs , General troubleshooting , How to , JavaScript , PDF forms
948
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 10, 2021 Sep 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);

 

View solution in original post

Translate
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 ,
Sep 10, 2021 Sep 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);

 

Translate
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 Beginner ,
Sep 10, 2021 Sep 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?

Translate
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 ,
Sep 10, 2021 Sep 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.

Translate
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 Beginner ,
Sep 10, 2021 Sep 10, 2021

Ok, I see. Thank you both Bernd and Nesa!

Translate
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 ,
Jul 12, 2025 Jul 12, 2025
LATEST

Hi Patricia,

I've run into similar issues with JavaScript calculations in forms. First, make sure that each "Total Output Current" field is actually returning a numeric value. If any of them are empty or returning text, it can silently break the calculation.

I faced the same problem while working on a simple online calculator where I had to handle rounding and decimal formatting. What helped was checking each value step by step using console.log to catch where things were going wrong.

If you’d like to see how I approached it, here’s the tool I built: https://lacalculadaradealicia.es

Hope this helps — good luck!

Translate
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