How to Fix PDF Form Calculations Treating Numbers as Text
Question details
The user needs to correct a PDF form calculation issue where mathematical addition functions act as string concatenation.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Designing or filling out interactive PDF forms with automated calculation scripts.
- Observed behavior
- When adding field values together, the numbers are processed as text strings, causing them to append rather than calculate mathematically (e.g., 10 + 0 results in 100 instead of 10).
Ensure you have permission to edit the interactive form fields within your PDF editor and verify that none of the inputs contain unintended spaces, currency symbols, or non-numeric characters.
Convert Field Values Using JavaScript Functions
Force the PDF form to treat text field inputs as numeric values by explicitly parsing them in the custom calculation script.
By default, PDF form fields evaluate inputs as text strings. If you attempt to add these values together using a standard plus sign, the program simply joins the text together. By enforcing a numeric conversion within your script, you prevent this accidental concatenation.
Open your PDF file in your editor and navigate to the Form Editing or Prepare Form mode to view interactive fields.
Right-click the target field where the calculation result will appear and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab and choose 'Custom calculation script', then click the 'Edit' button.
Wrap your field value retrieval variables in a Number() or parseFloat() function. For example: var val1 = Number(this.getField('Text1').value);
Write out your addition formula (e.g., event.value = val1 + val2;) and click 'OK' or 'Close' to save the new properties.
Set Field Formatting to Number Category
Configure the properties of both your input and output fields to recognize the entered data strictly as numbers rather than plain text.
Easily Design and Calculate PDF Forms with WPS Office
WPS PDF Editor provides a comprehensive set of tools for creating interactive forms. You can easily define field properties, manage calculation scripts, and ensure your data behaves exactly as intended without wrestling with complex formatting.
- 1. Open PDF in WPS Office: Launch WPS Office and open the PDF form you wish to edit.
- 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal interactive field controls.
- 3. Insert or select fields: Click on 'Text Field' to insert a new box, or simply double-click an existing field.
- 4. Set calculation properties: In the Properties window, use the 'Format' and 'Calculate' tabs to establish numeric rules and automated math functions.

Frequently Asked Questions
Why does my PDF form show NaN when calculating?
NaN stands for 'Not a Number'. This typically occurs if one of your calculation fields is left blank or contains non-numeric text. You can resolve this by adding a script condition to treat empty fields as a zero value.
Can I do basic addition in a PDF form without using JavaScript?
Yes, standard PDF editors allow you to use built-in functions. In the field properties under the Calculate tab, select 'Value is the sum (+) of the following fields' and pick the target fields, avoiding custom code entirely.
Do currency symbols interfere with PDF field calculations?
Yes. If a user manually types a currency symbol or a comma into an input field, the calculation script may process the entire input as text. It is best practice to set the field's Format category to 'Number' or 'Currency' in the properties, so the symbol is handled automatically by the software rather than the user's keystrokes.




