How to Leave a PDF Calculation Field Blank When the Result is Zero
Question details
The user needs to configure a PDF form calculation to display an empty field instead of a zero when the calculated result is zero.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating and formatting dynamic PDF forms with automatic mathematical calculations.
- Observed behavior
- By default, form fields display a '0' when a calculation yields zero. The goal is to keep the field visibly blank to avoid a cluttered document appearance.
Ensure you are using a PDF editor that supports form creation and custom JavaScript calculations. Take note of the exact names of the input fields you want to calculate.
Use a Custom Calculation Script to Hide Zero Results
Apply a simple JavaScript snippet to your calculation field to check if the result is zero, and return an empty string if true.
Standard built-in calculation functions in PDF forms will invariably output a zero if the input fields are empty or mathematically resolve to zero. To bypass this, you must replace the standard calculation with a custom JavaScript snippet.
Right-click the specific calculation result field in your PDF form editor and select 'Properties' from the context menu.
In the Field Properties dialog box, click on the 'Calculate' tab to view calculation options.
Select the 'Custom calculation script' radio button and click the 'Edit' button next to it.
Input the following script: var a=Number(this.getField("Field1").valueAsString); var b=Number(this.getField("Field2").valueAsString); event.value=(a==0 || b==0) ? "" : a*b; Be sure to replace "Field1" and "Field2" with your actual field names.
Click 'OK' to save the script, close the properties window, and test your form by entering values that result in zero to verify the field remains blank.

Manage and Fill Complex PDF Forms with WPS Office
WPS PDF provides a comprehensive and user-friendly set of tools for viewing, filling, and managing dynamic PDF forms, ensuring perfect execution of complex scripts and calculations.
- 1. Open the PDF Form: Launch WPS Office and open your interactive PDF document using the integrated WPS PDF tool.
- 2. Interact with Fields: Click on the designated form fields to input your data. WPS PDF will automatically process any embedded calculation scripts.
- 3. Save or Share: Once your form is filled and calculations are verified, click 'Save' to keep your data, or export the document to share it securely.

Frequently Asked Questions
Why does my PDF calculation field show a zero instead of staying blank?
By default, mathematical operations in standard PDF forms will output '0' if the input fields are empty or their product/sum is zero. A custom script is required to override this native behavior.
Can I use standard calculation options to hide zeros?
No, the standard 'Value is the sum/product of' option in PDF form properties does not feature a built-in toggle to hide zeros. You must utilize the 'Custom calculation script' option.
What if my form involves adding multiple fields?
You can easily expand the JavaScript snippet to declare variables for each field you need to add, calculate their sum, and use a ternary operator to set the event.value to an empty string ("") if the total equals zero.
Will these calculation scripts work in all PDF viewers?
Most modern desktop PDF editors and viewers, including WPS PDF and Adobe Acrobat, fully support JavaScript. However, some basic browser-based PDF readers or mobile viewers may not execute these calculation scripts correctly.




