PDF Editing Issues

How to Return "Zero" Instead of "Dollars and Zero Cents" in PDF JavaScript

Amos GikundaAmos Gikunda Nov 5, 2026 869 views

Question details

The user needs to modify a PDF form calculation script so that when a numeric field evaluates to 0, the output displays strictly as "Zero" rather than the standard formatted currency string.

How to Return "Zero" Instead of "Dollars and Zero Cents" in PDF JavaScript
Product
Adobe Acrobat PDF
Device & OS
not provided
Scenario
Formatting numeric values into text strings within a PDF form using custom JavaScript calculations.
Observed behavior
The amount-to-words script currently formats the numeric input 0 as "Dollars and Zero Cents" instead of outputting a clean "Zero".
Before you start

Ensure you have access to the PDF form's calculation scripts and verify the exact internal name of the numeric input field you need to evaluate.

Solution 1Recommended

Intercept the Zero Value Before Currency Conversion

Add a conditional check to your script that handles the zero value independently before it reaches the main formatting function.

This is the most straightforward method because it prevents the currency-formatting function from executing at all if the input is zero, effectively bypassing the default formatting behavior.

1
Open form field properties

Open your PDF document in form editing mode, right-click the destination text field where the wording should appear, and select Properties.

2
Access the custom calculation script

Navigate to the Calculate tab, select "Custom calculation script", and click Edit.

3
Add the conditional script

Insert the following logic: var f = this.getField("Number"); if (Number(f.value) == 0) event.value = "Zero"; else event.value = ConvertToWords(f.value);

Intercept the Zero Value Before Currency Conversion
Update field names: Be sure to replace "Number" with your actual source field name, and "ConvertToWords" with the exact name of the conversion function used in your document.
Advanced PDF Form Editing

Build and Edit Smart PDF Forms Seamlessly with WPS Office

WPS Office offers comprehensive PDF tools, including form field creation, editing, and JavaScript calculation support, making it simple to build smart, automated documents and handle precise value calculations.

  1. 1. Open your PDF file: Launch WPS Office and open the interactive PDF form you wish to modify.
  2. 2. Navigate to the Form tab: Click on the Form tab in the top navigation ribbon to access form controls, properties, and calculation settings.
  3. 3. Edit fields and scripts: Double-click any text field to adjust calculation scripts or set up field dependencies, then preview to ensure accurate formatting.
Create and modify interactive PDF form fields instantlyFull support for JavaScript to calculate dynamic PDF formsHighly compatible with Adobe Acrobat PDF formats and scriptsLightweight software architecture for faster processing
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF script format empty fields as zero dollars?

In PDF JavaScript calculations, an empty or null number field often evaluates automatically as '0'. If your amount-to-words function applies default currency formatting to all numeric values without an explicit exception for 0, it will output "Dollars and Zero Cents".

Does WPS Office support document-level JavaScript for PDFs?

Yes, WPS PDF allows you to process standard PDF forms that utilize embedded JavaScript, meaning custom formatting calculations will operate reliably across major PDF editing platforms.

How do I test my updated JavaScript calculation in the PDF?

Switch your PDF editor from Form Editing mode back to Preview or Hand tool mode. Input various test numbers—including 0, 1, and blank—into your source text field, and verify that the target calculation field outputs the correct text string.