PDF Editing Issues

Format PDF Form Fields: Display Integers Without Decimals

John WilsonJohn Wilson Nov 5, 2026 871 views

Question details

The user wants to format a calculated PDF form field so that integer results appear as whole numbers without trailing zeros, while fractional results display exactly two decimal places.

How to Display Integers Without Decimals and Other Numbers With Two Decimal Places in PDF Forms
Product
PDF Editors
Device & OS
not provided
Scenario
Designing or editing a fillable PDF form with calculated fields that require intelligent number formatting for cleaner presentation.
Observed behavior
Standard PDF number formatting applies a fixed number of decimal places to all values, resulting in whole numbers inappropriately displaying decimals (e.g., 100.00 instead of 100).
Before you start

Ensure you are using a PDF editor that supports form creation and custom JavaScript execution, and that your document contains the target form fields.

Solution 1Recommended

Use a Custom Format Script with util.printf

Apply a custom JavaScript snippet to the form field's formatting properties to check if the value is an integer and format it conditionally.

This approach uses the built-in JavaScript function Number.isInteger to detect if the calculated result is a whole number. If it is not, it uses Acrobat's util.printf function to append exactly two decimal places.

1
Open form field properties

Enter the form editing mode in your PDF editor, right-click the target text field, and select 'Properties'.

2
Navigate to the Format tab

In the Properties dialog box, click on the 'Format' tab to access formatting options.

3
Select Custom Format

Click the 'Select Format Category' dropdown menu and choose 'Custom' from the list.

4
Insert the JavaScript code

In the Custom Format Script text box, enter the following code: if (!Number.isInteger(event.value)) event.value = util.printf("%.2f", event.value);

5
Save and test

Click 'Close' to save the properties, exit form editing mode, and enter different numbers to test the conditional formatting.

Use a Custom Format Script with util.printf
Formatting Results: This exact script cleanly displays whole numbers (like 100) without decimals, while automatically keeping two decimals for fractions (like 99.12).
Advanced PDF Editing

Manage Interactive PDF Forms with WPS Office

WPS Office offers a comprehensive PDF toolkit that makes editing forms, managing calculations, and reviewing complex documents effortless across all your devices.

  1. 1. Open your PDF form: Launch WPS Office and open your PDF document containing the calculated fields.
  2. 2. Access PDF tools: Navigate to the PDF toolset to interact with form fields and test your scripts.
  3. 3. Save your document: Once formatting is complete, save your customized interactive PDF to share.
View and edit interactive PDF forms with advanced formatting.Fully compatible with standard Adobe Acrobat PDF formats.Lightweight, fast-loading interface ideal for everyday office tasks.Cross-platform support for seamless workflow migration.
QA img-9

Frequently Asked Questions

Why do my whole numbers show .00 at the end in PDF forms?

This occurs when the field's Format category is set to 'Number' with exactly two decimal places. This default setting blindly applies decimals to all inputs, including integers. Using a Custom Format script resolves this issue.

Does the util.printf function work in all PDF readers?

The util.printf function is a standard Acrobat JavaScript method. It is supported by the majority of modern, advanced PDF readers that process JavaScript form calculations, ensuring consistent behavior for most users.

Can I apply this custom script to multiple fields simultaneously?

Yes. In your PDF editor's form mode, you can select multiple fields at once, right-click to open their combined Properties, and paste the Custom Format script. It will instantly apply to all selected fields.