Create an Acrobat Calculated Field That Rounds Down
Question details
Create a PDF form calculation that divides two fields, rounds down, and displays 1 when the rounded result is zero.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs a calculated output based on two numeric input fields.
- Observed behavior
- The output should show the rounded-down quotient, replacing a result of zero with 1.
Open the PDF in an Acrobat version that can edit form fields, and confirm the exact names of the two input fields and the output field. Enable JavaScript in Acrobat preferences if it is disabled.
Add a custom calculation script to the output field
Use Acrobat JavaScript to divide the input values, round down, and replace a zero result with 1.
In Acrobat, open the PDF and select All tools > Prepare a form. Make sure the form contains two input fields and an output field.
Right-click the output field, select Properties, and open the Calculate tab. Select Custom calculation script and click Edit.
Paste this script, replacing Field A and Field B with your input field names: var aField = this.getField("Field A"); var bField = this.getField("Field B"); var aText = aField.valueAsString.replace(/^\s+|\s+$/g, ""); var bText = bField.valueAsString.replace(/^\s+|\s+$/g, ""); event.value = ""; if (aText !== "" && bText !== "") { var a = Number(aField.value); var b = Number(bField.value); if (isFinite(a) && isFinite(b) && b !== 0) { var result = Math.floor(a / b); event.value = result === 0 ? 1 : result; } }
Click OK to close the script editor and field properties, then save the PDF. Enter values in Field A and Field B, including a zero numerator, a zero denominator, and blank inputs.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes it easy to bring existing files into one workspace, but it does not replace Acrobat's custom JavaScript calculation workflow.

Frequently Asked Questions
Where do I enter the calculation script in Acrobat?
Select All tools > Prepare a form, right-click the output field, and choose Properties. On the Calculate tab, select Custom calculation script and click Edit.
What happens if the denominator is zero or an input is blank?
The script leaves the output field blank in either case. This avoids division by zero and prevents a blank input from being treated as a valid zero.
Does rounding down always mean rounding toward zero?
No. Math.floor rounds toward negative infinity. For example, Math.floor(-1.2) returns -2, while Math.floor(1.2) returns 1.
Will the calculation work in every PDF viewer?
Not necessarily. The viewer must support and allow Acrobat form JavaScript. Test the saved PDF in the viewer your recipients will use.




