Display Integers Without Decimals in an Adobe Acrobat Number Field
Question details
Format a PDF form field so whole numbers appear without decimals and other numbers appear with two decimal places.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form uses a comma as the decimal separator and should display values such as 5,12 and 5.
- Observed behavior
- The desired field format shows two decimal places for non-whole values and no decimal separator or trailing zeros for whole numbers.
Open the PDF in an Acrobat version that lets you edit form fields, and confirm that the field is editable. The script below accepts a comma or period as the decimal separator but does not accept thousands separators.
Apply a custom format script to the Acrobat form field
Use a custom format script to show whole numbers without decimals and other values with two decimal places.
The script formats values for display using a comma as the decimal separator. Values are rounded to two decimal places; if the rounded result is a whole number, its decimal portion is removed.
In Acrobat, open the PDF and choose All tools > Prepare a form. Right-click the number field and select Properties.
Open the Format tab, choose Custom from the format category menu, and click Edit next to Custom Format Script.
In the script editor, enter: var s = String(event.value); if (/^\s*[-+]?\d+(?:[.,]\d+)?\s*$/.test(s)) { var n = Number(s.replace(',', '.')); if (isFinite(n)) { var f = n.toFixed(2); event.value = /\.00$/.test(f) ? f.replace(/\.00$/, '') : f.replace('.', ','); } }
Click OK, close the field properties, and save the PDF. Exit form editing and enter 5, 5,1, and 5,12 in the field; after leaving the field, they should display as 5, 5,10, and 5,12.

Prepare formatted number data with WPS Office
WPS Office is a free, lightweight alternative for working with spreadsheet data and exporting documents to PDF. Its familiar interface and Microsoft Office format compatibility make it easy to move existing files, but it does not replace the Acrobat JavaScript needed for this interactive PDF field.

Frequently Asked Questions
Where do I add the format script in Acrobat?
Choose All tools > Prepare a form, right-click the field, and select Properties. On the Format tab, choose Custom and click Edit next to Custom Format Script.
How can I display a period instead of a comma?
In the script's final assignment, replace f.replace('.', ',') with f. Non-whole values will then display with a period, such as 5.12.
Will a value such as 5,1 display with two decimal places?
Yes. With the supplied script, entering 5,1 displays as 5,10 after you leave the field. Entering 5 displays as 5.
Does the script prevent invalid entries?
No. The format script changes supported numeric values for display but leaves unsupported input unchanged. Use the field's Validate tab or a separate validation script if you need to reject invalid entries.
Will the formatting work in every PDF viewer?
Not necessarily. The viewer must support the Acrobat JavaScript used by the form. Test the saved PDF in the viewer your recipients plan to use.




