PDF Editing Issues

How to Round a PDF Form Value to the Nearest Whole Number

Chanuka GeekiyanageChanuka Geekiyanage Nov 3, 2026 869 views

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.

How to Round a PDF Form Value to the Nearest Whole Number
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

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.

2
Navigate to the Calculate Tab

In the Properties window, click on the 'Calculate' tab and select the 'Custom calculation script' radio button.

3
Enter the Rounding Script

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.

4
Save and Test

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.

Use JavaScript to Round the Source Field Value
Formatting Tip: If you need specific currency symbols or thousand separators for the rounded number, configure the destination field's format settings separately under the 'Format' tab.
Edit and Calculate PDF Forms

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. 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document. Navigate to the 'Form' tab on the top ribbon.
  2. 2. Add Form Fields: Click on 'Text Field' to draw your source and destination boxes onto the document.
  3. 3. Apply Calculation Scripts: Double-click the destination field to open properties, switch to the 'Calculate' tab, and input your JavaScript code for rounding.
Fully supports custom JavaScript for advanced PDF form calculations like rounding.Create fillable PDF forms with interactive text boxes, checkboxes, and drop-down menus.Highly compatible with standard Adobe Acrobat PDF forms.Lightweight application with an intuitive, user-friendly interface.
microsoft office alternative - wps office

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.