How to Round a PDF Form Value to the Nearest Whole Number
Question details
The user needs to round a number entered or calculated in a PDF form field to the nearest whole integer and display the result automatically in another field.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms that involve totals, quantities, or calculated numerical values requiring whole numbers.
- Observed behavior
- Calculations or inputs may yield decimal values, but the desired outcome is to automatically process and display a rounded whole number in the destination form field.
Ensure you have the exact name of the source form field you wish to round, as JavaScript is case-sensitive and requires precise field mapping to execute correctly.
Use JavaScript to Round the Source Field Value
Apply a custom calculation script using Math.round() to pull the value from one field and display it as a rounded whole number in the destination field.
This method is ideal when you need to calculate totals or copy values from another field, ensuring the final output is stripped of decimals.
Open the PDF form in editing mode and double-click the destination field (where you want the rounded number to appear) to open its Properties dialog.
In the Properties window, click on the 'Calculate' tab and select the 'Custom calculation script' radio button.
Click the 'Edit' button and enter the following JavaScript code: event.value = Math.round(this.getField("Field1").value); Be sure to replace "Field1" with the exact name of your source field.
Click 'OK', close the Properties window, and exit form editing mode. Test the form by entering a decimal number in the source field to verify the destination field updates correctly.

Self-Rounding a Field's Own Value
Configure a form field to automatically round its own value as soon as the user enters a decimal number.
Create and Manage Smart PDF Forms with WPS Office
WPS PDF offers robust form editing features, allowing you to easily insert text fields, apply advanced calculation scripts, and format data to streamline your workflow.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document. Navigate to the 'Form' tab on the top ribbon.
- 2. Add Form Fields: Click on 'Text Field' to draw your source and destination boxes onto the document.
- 3. Apply Calculation Scripts: Double-click the destination field to open properties, switch to the 'Calculate' tab, and input your JavaScript code for rounding.

Frequently Asked Questions
Why is my JavaScript calculation not working in the PDF form?
This usually happens if the field names in your script do not exactly match the actual field names (JavaScript is highly case-sensitive), or if the calculation order of your PDF form fields is set up incorrectly.
How do I round to a specific number of decimal places instead of a whole number?
To round to two decimal places, modify the script to: event.value = Math.round(this.getField("Field1").value * 100) / 100; You can adjust the multipliers (e.g., 1000 for three decimal places) based on your needs.
Can I format the rounded whole number as a currency?
Yes. After setting up the calculation script, go to the 'Format' tab in the destination field's properties. Select 'Number' or 'Custom' to choose your preferred currency symbol and formatting style.
Will this JavaScript rounding script work on mobile PDF readers?
Support for PDF JavaScript varies by mobile app. While it works reliably on desktop software like WPS PDF and Adobe Acrobat, many basic mobile PDF viewers lack the engine to execute calculation scripts.




