Count Decimal Places in an Adobe Acrobat Form
Question details
The user needs an Acrobat form field to count the digits after the decimal point in another field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- An interactive PDF form should calculate a decimal-place count from a source field.
- Observed behavior
- The desired count is 1 for 10.1, 2 for 10.01, 3 for 10.001, and 0 for a whole number.
Open the PDF in an Acrobat edition that can edit form fields, and identify the exact name of the field containing the value. The script below expects a period as the decimal separator.
Add a custom calculation script to the result field
Use Acrobat's form calculation options to count the characters after the decimal point in a source field.
In Adobe Acrobat, open the PDF and choose All tools > Prepare a form.
Select the source field and check its name in Properties. Create or select a separate text field to display the count.
Open the result field's Properties, select Calculate, choose Custom calculation script, and click Edit. Enter: var x = this.getField("Text1").valueAsString; var decimal = x.split("."); event.value = decimal.length > 1 ? decimal[1].length : 0;
In the script editor, replace Text1 with the exact name of your source field, then confirm the script and close Properties.
Select Preview in Prepare a form and enter 10.1, 10.01, 10.001, and 10 in the source field. Check that the result field displays 1, 2, 3, and 0, respectively.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative for everyday document, spreadsheet, presentation, and PDF work. Its familiar interface and support for Microsoft Office formats make it easy to move existing files. It does not fix or replace the Acrobat-specific form calculation script above.

Frequently Asked Questions
Why does the script return zero for a whole number?
The script splits the field's text at the period. If there is no period, it sets the result field to 0.
Where do I enter the field calculation script?
In Acrobat, open All tools > Prepare a form, open the result field's Properties, and select Calculate > Custom calculation script > Edit.
Will the script count trailing zeros?
It counts trailing zeros only if they are present in the text returned by the source field's valueAsString property. Check the field's formatting and test a value such as 10.00.
Can I use a comma as the decimal separator?
The provided script looks for a period. If your field consistently uses a comma instead, change split(".") to split(",") and test the form with your expected input.




