How to Remove Decimal Places by Rounding Down Using JavaScript in PDF Forms
Question details
The user needs to round down numerical values (e.g., converting 2.30 or 2.90 to 2) to remove decimal places within a fillable PDF form field.

- Product
- Device & OS
- not provided
- Scenario
- Setting up form field calculations and validation rules in a PDF document to ensure user input strictly rounds down to whole numbers.
- Observed behavior
- Custom format scripts are only altering the visual display of the number without changing the actual stored value, leaving the decimals intact in the underlying data.
Ensure your PDF editor supports JavaScript editing for form fields and that you have administrative access to modify the document's properties.
Apply a Custom Validation Script Using Math.floor
Use a validation script rather than a formatting script to physically alter the field's underlying data by rounding it down to the nearest whole number.
A custom format script only changes how a field's value appears on the screen. It does not alter the actual data being stored or submitted. To physically convert values like 2.90 to 2, you must utilize a validation or calculation script.
The JavaScript Math.floor() function takes the provided number and rounds it down toward negative infinity, ensuring all decimal places are permanently removed from the actual value.
Open your PDF in form editing mode, right-click the specific number field you want to modify, and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Validate' tab to set up rules for the data entered into this field.
Select the option for 'Run custom validation script' and click the 'Edit' button. Enter the following code exactly: event.value = Math.floor(Number(event.value));
Click 'OK' to save the script, close the properties window, and exit form editing mode. Test the field by typing a number with decimals to confirm it rounds down automatically.

Create, Edit, and Manage PDF Forms with WPS Office
If you are working with complex PDF documents, WPS Office offers a powerful PDF editor that makes managing form fields, editing text, and securing documents straightforward and accessible.
- 1. Download and Install: Download WPS Office from the official website and complete the installation on your device.
- 2. Open Your PDF: Launch WPS Office and open your PDF document using the built-in PDF editor.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form creation and management tools.
- 4. Save Your Changes: After adjusting your form fields, click 'Save' or 'Export to PDF' to secure your changes.

Frequently Asked Questions
Why doesn't a format script change my actual PDF field value?
A format script is designed solely to alter the visual presentation of a field (such as adding currency symbols or standardizing date formats). To change the actual underlying data that gets submitted or used in other formulas, you must use a validation or calculation script.
What is the difference between Math.floor() and Math.round() in JavaScript?
The Math.floor() function always rounds a number down to the nearest integer, meaning 2.90 becomes 2. Conversely, Math.round() rounds a number to the nearest integer, so 2.90 would become 3, and 2.40 would become 2.
How can I stop users from typing letters into a numeric PDF field?
To prevent letters or special characters from being entered, you need to apply a custom keystroke script to the field. Keystroke scripts evaluate user input in real time and can block non-numeric characters before they are even registered in the box.




