PDF Editing Issues

When to Use the Plus Sign with Acrobat JavaScript Field Values

Ayan MasoodAyan Masood Nov 25, 2026 868 views

Question details

Determine when to prefix an Acrobat JavaScript field value with a plus sign and how the conversion affects leading zeros.

When to Use the Plus Sign with Acrobat JavaScript Field Values
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the calculation script

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.

2
Convert and validate the value

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.

3
Test the form

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.

Use Unary Plus for Numeric Calculations
Empty values need a check: Unary plus converts an empty or whitespace-only string to 0. Check for an empty value first if a blank field should not count as zero.
Free Microsoft Office alternative

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.

Open and work with PDF documents in the same office suiteCompatible with Microsoft Office formats including DOCX and XLSXFamiliar interface for a straightforward transition from Microsoft OfficeFree, lightweight tools for everyday document work
QA img-9

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.