Truncate PDF Form Numbers to Three Decimal Places in Adobe Acrobat
Question details
Set a PDF form field to accept values from 0 to 100 and truncate any digits beyond three decimal places.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A user is configuring a numeric PDF form field that must preserve up to three decimal places without rounding.
- Observed behavior
- The field should reject values outside the allowed range and remove extra decimal digits from valid values.
Open the PDF in a version of Adobe Acrobat that can edit form fields, and identify the field you want to validate. The script below uses a period as the decimal separator and does not accept signs, commas, or scientific notation.
Add a custom validation script to the PDF form field
Use this method to check the original value against the range and truncate extra decimals when the user commits the field.
In Adobe Acrobat, open the PDF and select All tools > Prepare a form. Select the numeric text field and open its Properties.
In the field's Format tab, choose None so a number format does not round the displayed value.
In the Validate tab, select Run custom validation script, click Edit, and enter the following script: var value = String(event.value).replace(/^\s+|\s+$/g, ""); if (value !== "") { if (!/^(?:\d+(?:\.\d*)?|\.\d+)$/.test(value)) { app.alert("Enter a number between 0 and 100."); event.rc = false; } else { var parts = value.split("."); var whole = (parts[0] || "0").replace(/^0+(?=\d)/, ""); var fraction = parts[1] || ""; if (whole.length > 3 || (whole.length === 3 && whole > "100") || (whole === "100" && /[1-9]/.test(fraction))) { app.alert("Enter a number between 0 and 100."); event.rc = false; } else { var dot = value.indexOf("."); event.value = dot < 0 ? value : value.slice(0, dot + 4); } } }
Close Properties, save the PDF, and enter test values in the field. For example, 12.3456 should become 12.345, while 100.0001 should be rejected.

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 Microsoft Office files. Its format compatibility makes it easier to move existing documents into your workflow. Use Acrobat and a compatible PDF viewer for the custom form validation script described above.

Frequently Asked Questions
Does the script check the range before truncating?
Yes. It checks the entered value first, so 100.0001 is rejected rather than changed to 100.000.
Why should I set the field format to None?
In the field's Properties > Format tab, choose None to prevent number formatting from rounding the displayed value independently of the validation script.
Can users leave the field blank?
Yes. The script allows an empty value. To require an entry, open the field's Properties > General tab and select Required.
Will the validation work in every PDF viewer?
No. The viewer must support Acrobat form JavaScript and have JavaScript enabled. Test the saved PDF in the viewer your users will use.




