PDF Editing Issues

How to Remove Decimal Places by Rounding Down Using JavaScript in PDF Forms

Emma BrownEmma Brown Nov 5, 2026 871 views

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.

How to Remove Decimal Places by Rounding Down Using JavaScript in PDF Forms
Product
PDF
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.
Before you start

Ensure your PDF editor supports JavaScript editing for form fields and that you have administrative access to modify the document's properties.

Solution 1Recommended

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.

1
Access Field Properties

Open your PDF in form editing mode, right-click the specific number field you want to modify, and select 'Properties' from the context menu.

2
Navigate to the Validate Tab

In the Properties dialog box, click on the 'Validate' tab to set up rules for the data entered into this field.

3
Enter the JavaScript Code

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));

4
Save and Test

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.

Apply a Custom Validation Script Using Math.floor
Restricting Keystrokes: While validation changes the final value, it does not stop users from typing invalid characters. If you need to restrict what users can physically type into the box, you will also need to implement a custom keystroke script.
Comprehensive PDF Editor

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. 1. Download and Install: Download WPS Office from the official website and complete the installation on your device.
  2. 2. Open Your PDF: Launch WPS Office and open your PDF document using the built-in PDF editor.
  3. 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form creation and management tools.
  4. 4. Save Your Changes: After adjusting your form fields, click 'Save' or 'Export to PDF' to secure your changes.
Easily create and manage interactive fillable PDF forms.Fully compatible with standard Adobe Acrobat PDF formats.Lightweight program offering smooth performance on any device.Seamlessly convert files between PDF, Word, Excel, and PowerPoint.
microsoft office alternative - wps office

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.