How to Return a Blank Value for a Zero Denominator in Acrobat PDF
Question details
The user needs to calculate a percentage in a PDF form but wants to avoid a divide-by-zero error by returning a blank value when the denominator is zero.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Calculating percentages or dynamic division results within an interactive PDF form.
- Observed behavior
- Dividing by zero without conditional checks results in an error or an 'Infinity' value instead of leaving the field cleanly blank.
Ensure you have access to the PDF form in editing mode and that your calculation text fields are properly named so you can reference them accurately in the script.
Use a Custom Calculation Script to Test for a Zero Denominator
Implement JavaScript to check if the denominator field is zero before performing the calculation, returning an empty string if true.
In JavaScript, dividing by zero does not automatically produce a blank field. By using conditional logic (if/else statements), you can intercept the zero value and instruct the PDF form to display nothing instead of an error.
Open your PDF in Adobe Acrobat, navigate to the 'Prepare Form' tool, and double-click the target field where you want the percentage or division result to appear.
In the Text Field Properties dialog box, click on the 'Calculate' tab, then select the 'Custom calculation script' option.
Click the 'Edit' button and paste the following code, replacing 'CT-TPE' and 'CT-TPV' with your actual field names: var a = Number(this.getField("CT-TPE").valueAsString); var b = Number(this.getField("CT-TPV").valueAsString); if (b == 0) event.value = ""; else event.value = a / b;
Click 'OK' to close the JavaScript editor, then close the Properties window. Enter '0' in your denominator field to verify that the target field remains blank.

Edit PDF Forms and Calculations Seamlessly with WPS Office
WPS Office provides a comprehensive suite of PDF editing tools, allowing you to create, fill, and manage interactive PDF forms effortlessly. You can easily modify form fields, perform calculations, and manage your documents safely.
- 1. Open WPS Office: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access Form Editing Tools: Navigate to the 'Form' tab on the top ribbon to view available interactive field options and properties.
- 3. Modify Fields and Save: Select the text fields you want to configure, adjust their properties as needed, and save your document to apply the changes.

Frequently Asked Questions
Why do I get an error when dividing by zero in a PDF form?
In mathematics and programming languages like JavaScript, division by zero is undefined. By default, it typically returns an 'Infinity' value or throws a calculation error. A custom script intercepts this to display a blank field instead.
Can I use Simplified Field Notation instead of custom JavaScript?
No. Simplified field notation only supports basic arithmetic and cannot handle conditional logic like checking 'if denominator is zero'. You must use a custom calculation script for this specific scenario.
Does WPS Office support interactive PDF form filling?
Yes, WPS Office fully supports reading, filling, and printing interactive PDF forms, making it a highly compatible and efficient tool for managing professional PDF documents.




