Remove Decimal Places from a PDF Form Field in Acrobat JavaScript
Question details
Display only the integer portion of a number in an Acrobat PDF form field without leaving a decimal point.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A PDF form uses JavaScript to remove decimal digits from a numeric field.
- Observed behavior
- The script removes the decimal digits but leaves a trailing decimal point, displaying a value such as 36. instead of 36.
Open the PDF in a version of Acrobat that supports editing form fields, and identify the field whose displayed value needs to change. Check whether its values can be negative, because Math.floor() does not truncate negative numbers toward zero.
Truncate the displayed value with a custom format script
Use this approach to display the integer portion without rounding or a trailing decimal point, including for negative values.
A custom format script changes the field's displayed value; it does not necessarily change the value stored in the form. Math.floor() works for nonnegative numbers, while Math.ceil() truncates negative numbers toward zero.
In Acrobat, open the PDF and select Prepare a form. Right-click the target field and choose Properties.
Select the Format tab, choose Custom from the format category menu, and open Edit for the custom format script.
Replace the existing custom format script with: if (event.value !== "" && !isNaN(Number(event.value))) { var n = Number(event.value); event.value = n < 0 ? Math.ceil(n) : Math.floor(n); }
Close the script editor and field properties, save the PDF, and test the field with values such as 36.7 and -36.7. They should display as 36 and -36.

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 Microsoft Office format compatibility helps make migration straightforward, though it does not fix Acrobat form JavaScript.

Frequently Asked Questions
Why does my PDF field show 36. instead of 36?
The script may be removing digits after the decimal point while leaving the point itself. In the field's Properties > Format settings, use a custom format script that converts the value to a number and truncates it.
Does Math.floor() remove decimals from negative numbers?
Math.floor() rounds toward negative infinity, so Math.floor(-36.7) returns -37. To remove the decimal portion toward zero, use Math.ceil() for negative values and Math.floor() for nonnegative values.
Will a custom format script change the stored form value?
A custom format script controls how the field value is displayed and does not necessarily change its stored value. If the underlying value must also be an integer, adjust the relevant calculation or validation script and test the result.
Can I use Acrobat's number format with zero decimal places instead?
In the field's Properties > Format tab, you can choose Number and set decimal places to zero. This may round the value rather than truncate it, so use a custom script if you need to discard the fractional portion.




