How to Return "Zero" Instead of "Dollars and Zero Cents" in PDF JavaScript
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.

- 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".
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.
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.
Open your PDF document in form editing mode, right-click the destination text field where the wording should appear, and select Properties.
Navigate to the Calculate tab, select "Custom calculation script", and click Edit.
Insert the following logic: var f = this.getField("Number"); if (Number(f.value) == 0) event.value = "Zero"; else event.value = ConvertToWords(f.value);

Modify the Amount-to-Words Function Logic
Update the internal ternary operator logic of your existing document-level amount-to-words function to process zero explicitly.
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. Open your PDF file: Launch WPS Office and open the interactive PDF form you wish to modify.
- 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. Edit fields and scripts: Double-click any text field to adjust calculation scripts or set up field dependencies, then preview to ensure accurate formatting.

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.




