Calculate and Round a PDF Form Field in Adobe Acrobat
Question details
Calculate a consumption rate from two PDF form fields, display it to one decimal place, and ensure fields calculate in the correct order.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A PDF form divides a quantity field by an engine-hours field to calculate a consumption rate.
- Observed behavior
- The desired result is a correctly ordered calculation displayed to one decimal place, with no result when the divisor is zero.
Open the form in Adobe Acrobat with form-editing tools available. Check the exact names of the quantity, hours, and result fields in Prepare a Form; the example uses QTYCC1 and ENGHRS1 for the source fields.
Add a calculation script and set the field order in Acrobat
Use a custom Acrobat JavaScript calculation to divide the fields and display the result to one decimal place.
In Acrobat, open All tools > Prepare a form, then double-click the consumption-rate field to open its properties.
On the Calculate tab, select Custom calculation script and click Edit. Enter: var qty = Number(this.getField("QTYCC1").valueAsString); var hours = Number(this.getField("ENGHRS1").valueAsString); event.value = hours == 0 ? "" : (qty / hours).toFixed(1); Replace the field names if yours differ.
On the result field's Format tab, choose None so another field format does not override the script's one-decimal display. Close the field properties.
In Prepare a Form, open More > Set Field Calculation Order. If the quantity field is itself calculated, move it before the consumption-rate field, then confirm the order.
Use Preview in Prepare a Form and enter values in the quantity and hours fields. Confirm that the result shows one decimal place and is blank when hours is zero, then save the PDF.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility, making it easy to move existing files into one workspace. Use Acrobat to configure the custom PDF form script and calculation order described above.

Frequently Asked Questions
Why is the calculated field blank when hours is zero?
The script checks whether ENGHRS1 is zero and sets event.value to an empty string to avoid division by zero. Enter a nonzero hours value to calculate the rate.
How do I make sure the quantity calculates before the rate?
In Acrobat's Prepare a Form tool, choose More > Set Field Calculation Order and place the calculated quantity field before the consumption-rate field.
Does toFixed(1) always round upward?
No. toFixed(1) formats the result to one decimal place. Use Math.ceil(qty / hours) if the result must always round upward to a whole number.
Is Acrobat form scripting written in Java?
No. Acrobat form calculations use JavaScript, which is a different language from Java. Add the script through the result field's Calculate tab.




