PDF Editing Issues

How to Format Acrobat Calculated PDF Fields with Two Decimal Places

Emma BrownEmma Brown Nov 3, 2026 869 views

Question details

The user needs to configure a calculated PDF form field to display a hyphen when the value is zero or blank, and to show numbers with exactly two decimal places (e.g., 5.00) for non-zero values.

How to Format Acrobat Calculated Fields with Two Decimal Places
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating or modifying an interactive PDF form that involves automated calculations and requires specific accounting or financial number formatting.
Observed behavior
The goal state is that any calculated field resulting in zero appears as a hyphen (-), while any non-zero value strictly retains two decimal places.
Before you start

Ensure you have access to a professional PDF editor capable of running custom JavaScript, and keep a backup copy of your original PDF form before applying new scripts.

Solution 1Recommended

Apply Custom JavaScript for Conditional Number Formatting

Use a custom JavaScript snippet in the calculation properties of your PDF form field to check the value and dynamically apply either a hyphen or a formatted number.

Standard number formatting in PDF properties cannot simultaneously enforce two decimal places and replace zero values with a hyphen. Using a custom calculation script solves this by dynamically checking the field's resulting value.

The AFNumber_Format function is a built-in Acrobat JavaScript method that allows you to specify decimal limits and separator styles easily.

1
Open Field Properties

Right-click the target PDF form field in 'Prepare Form' mode and select 'Properties' from the context menu.

2
Navigate to the Calculate Tab

In the Properties window, click on the 'Calculate' tab to manage how the field derives its value.

3
Enter the Custom Script

Select the 'Custom calculation script' radio button and click 'Edit'. Paste the following code: if (event.value == 0) event.value = "-"; else { AFNumber_Format(2, 3, 0, 0, "", false); }

4
Apply and Test

Click 'OK' to save the script, then close the Properties window. Enter test data in the referenced fields to ensure non-zero values show two decimals and zeros show a hyphen.

Apply Custom JavaScript for Conditional Number Formatting
Understanding the Script: The arguments in AFNumber_Format(2, 3, 0, 0, "", false) specify the number of decimal places (2) and the separator style (3 represents standard comma/period formatting), ensuring consistent output.
Manage PDF Forms Easily

Create and Edit PDF Forms with WPS Office

WPS Office offers a comprehensive PDF editor that allows you to view, fill, and create interactive PDF forms effortlessly. It is an excellent tool for managing document calculations and field properties.

  1. 1. Open the PDF File: Launch WPS Office and open the PDF document containing your interactive forms.
  2. 2. Access Form Tools: Navigate to the 'Form' tab located in the top menu bar to reveal form editing features.
  3. 3. Edit Field Properties: Select the form field you wish to modify and adjust its settings directly from the properties panel.
  4. 4. Save the Form: Click 'Save' to apply your changes and ensure the interactive elements work perfectly across all devices.
Easily fill and manage interactive PDF formsHighly compatible with standard Adobe PDF formatsLightweight application with an intuitive user interfaceCross-platform support for Windows, Mac, and mobile devices
microsoft office alternative - wps office

Frequently Asked Questions

Why do my PDF form numbers drop the trailing zeros?

By default, PDF text fields often trim unnecessary zeros to save space. To force trailing zeros (like '5.00'), you must apply a specific number format in the field's formatting properties or utilize a custom JavaScript function like AFNumber_Format.

How do I format a standard number field without scripts?

Right-click the field, choose Properties, navigate to the Format tab, select 'Number' as the format category, and set the decimal places to 2. However, note that this standard method will show '0.00' instead of a hyphen for zero values.

Does the custom JavaScript format work on all PDF readers?

Advanced JavaScript functions rely on the PDF JavaScript API. While they will work perfectly in professional desktop editors like Adobe Acrobat and WPS PDF, they may fail to execute in basic web browser viewers or simple mobile PDF apps.