When to Use the Plus Sign with Acrobat JavaScript Field Values
Question details
Determine when to prefix an Acrobat JavaScript field value with a plus sign and how the conversion affects leading zeros.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form script reads a field and may need to use its value in a numeric calculation.
- Observed behavior
- Unary plus converts a numeric-looking field value to a number; for example, the string "0001" becomes 1.
Open the PDF in Adobe Acrobat and check the exact field name under Prepare a form. Decide whether the value represents a quantity for calculation or an identifier whose leading zeros must be preserved.
Use Unary Plus for Numeric Calculations
Convert a numeric-looking field value when you need to perform arithmetic rather than preserve its text representation.
Acrobat field values can be strings or numbers depending on the field and its contents. Unary plus converts the value to a JavaScript number, so "0001" becomes 1 and nonnumeric text becomes NaN.
In Acrobat, open Prepare a form, select the output field, and open its Properties. On the Calculate tab, choose Custom calculation script and select Edit.
Enter a script such as: var f = this.getField("num.CD.BPAC.01"); var s = f ? f.valueAsString.replace(/^\s+|\s+$/g, "") : ""; event.value = s !== "" && isFinite(+s) ? +s : ""; Replace the field name with your own. Use the converted number in further arithmetic as needed.
Close the script editor and field properties, then enter a value such as 0001 in the source field. Check that the output is 1; an empty or nonnumeric value produces a blank output with this script.

Keep the Field Value as Text to Preserve Leading Zeros
Use the string value without unary plus when the field contains an identifier or code rather than a quantity.
Edit PDF Documents with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. It makes moving between common document formats straightforward, although it does not replace Acrobat's JavaScript form scripting.

Frequently Asked Questions
What does the plus sign before a field value do?
It is JavaScript's unary plus operator. For example, +this.getField("Field1").value converts a numeric-looking value to a number, so "0001" becomes 1.
How can I keep leading zeros in a PDF form field?
Read the field with this.getField("Field1").valueAsString and avoid numeric conversion. Also check that the field's formatting does not remove the zeros.
What happens if the field is blank or contains text?
Unary plus converts an empty or whitespace-only string to 0, while nonnumeric text becomes NaN. Check for a blank value and validate the converted number before using it in a calculation.
Where do I add a custom calculation script in Acrobat?
Open Prepare a form, select the calculated field, and open Properties. On the Calculate tab, choose Custom calculation script and select Edit.




