Skip to main content
Participating Frequently
March 8, 2019
Answered

Percentage Calculations

  • March 8, 2019
  • 2 replies
  • 9882 views

Hi experts,

I would highly appreciate it if anyone can help me with this:

I need to do percentage calculations of two fields in PDF Form. The percentage should show in a third field.

I’ve a number of students and I need to show in percentage how many got A+ and in another field A, etc.

Thanks in advance for your help.

BdxGZk.jpg

Correct answer try67

Number1 is not defined

1:Field:Calculate

ReferenceError: Number1 is not defined

1:Field:Calculate

This is what I did:

Number1/TotalNumber.

I'm just learning to do this & I know I'm doing a lot of mistakes doing this calculation. All others are working fine with me.

Endlessly appreciate you time and support.


Use this code:

var v1 = Number(this.getField("Number1").valueAsString);

var v2 = Number(this.getField("TotalNumber").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

2 replies

Participant
September 7, 2025

hi,

for percentage calculations in pdf forms, you can use a custom javascript like: event.value = (this.getfield("field1").value / this.getfield("field2").value) * 100; but make sure to handle zeros to avoid errors. if you need to verify the math outside adobe, try this free online percentage calculator: https://fcalculator.com/percentage-calculator.html - it shows step-by-step and can help test your formulas quickly.

hope that helps!

try67
Community Expert
Community Expert
March 8, 2019

This can be done with a simple script, but I would recommend you rename your fields to something a bit more consistent.

For example, if you renamed them to Number1, Number2, down to Number15, and Perc1, Perc2, etc., then you could use this code as the custom calculation script of the Perc1 script:

var total = 0;

for (var i=1; i<=15; i++) {

    total+=Number(this.getField("Number"+i).valueAsString);

}

it (total==0) event.value = "";

else event.value = Number(this.getField("Number1").valueAsString)/total;

This code can be extrapolated into a more generic function and then called from each of the Perc fields, instead of copying and pasting it (and changing the name of the field in the last line), but that's the basic way of doing it.

AbureeshAuthor
Participating Frequently
March 9, 2019

Thanks a lot for your  prompt help. Unfortunately, I'm not as professional as your are. I tried it but couldn't figure out how-to.

I changed the field as you recommended adding an extra raw for Totals of Numbers and Percentage. Each one in a separate field. as shown in the image below. The field TotalNumber is the SUM of all Number Fields. The same with PercTotal Field.

Is it possible to get the Percentage of Students who got, let's say, A+ or any other grade via dividing the total in "TotalNumber" by the number in the "Number#s" to reflect the Percentage in the "Perc" field corresponding the "Number" field of the same raw?

op7YUg.jpg

try67
Community Expert
Community Expert
March 9, 2019

Sure, that's possible as well. You just need to make sure the total is not zero before you apply the calculations, as division by zero is not an allowed operation.