How to Prevent Adobe Acrobat PDF Barcode from Rounding Long Numbers
Question details
The user needs to stop Adobe Acrobat PDF barcode scripts from altering or rounding long numerical values (like serial numbers).

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Generating barcodes via JavaScript calculations within a PDF document.
- Observed behavior
- Long numeric text-field values are treated as JavaScript numbers and converted into floating-point numbers, causing the barcode script to round them and lose precision.
Ensure you have access to the JavaScript form editor in your PDF software and that your form fields are properly named before modifying the barcode calculation scripts.
Use the valueAsString Property in the JavaScript Code
Modify your PDF barcode calculation script to retrieve the form field data as a string, preventing the system from automatically treating it as a mathematical number.
When standard JavaScript `.value` calls are used to read numeric form fields, the application converts long digit sequences into floating-point numbers. Since floating-point numbers have limited mathematical precision, values like long serial numbers get truncated and rounded.
By switching to strict string handling, you ensure that the application reads the exact sequence of inputted characters without applying any mathematical conversion.
Open your PDF file containing the barcode and enter the form editing or form preparation mode.
Right-click the specific barcode form field and select 'Properties' from the context menu.
Navigate to the 'Calculate' tab and click on the 'Edit' button next to your custom calculation script.
Find the line reading the text field, such as `this.getField("SerialNumberRow3").value`, and change `.value` to `.valueAsString`.
Click 'OK' to save the script, exit form editing mode, and test the barcode generation to confirm the full number is accurately preserved.

Manage and Edit PDF Forms with WPS Office
WPS Office provides a highly capable PDF editor that allows you to manage interactive PDF forms, text fields, and document properties seamlessly. Enjoy smooth document processing and industry-standard format compatibility.
- 1. Launch WPS PDF: Open WPS Office on your device and select the 'PDF Edit' tool from the main workspace to begin.
- 2. Open the Document: Click 'Open' and import your interactive PDF form or document into the secure editor workspace.
- 3. Process the Forms: Navigate to the 'Form' tab to confidently interact with text fields, dropdowns, and checkboxes, ensuring your data is filled flawlessly.

Frequently Asked Questions
Why does JavaScript in PDFs automatically round long numbers?
Standard JavaScript handles numeric data using a double-precision floating-point format. When a numeric sequence exceeds 15 digits (known as the maximum safe integer limit), it loses precision and the lowest order digits are automatically rounded by the system.
Will appending a space corrupt my barcode scanner data?
Appending a space forces the PDF script to treat the number as a literal text string, which effectively solves the rounding issue. However, you must ensure that your external barcode scanning software is configured to ignore or trim trailing spaces to prevent data processing errors.
Does the valueAsString property work reliably on all PDF readers?
The `.valueAsString` property is widely supported in most modern, fully-featured PDF readers that support JavaScript form calculations. Basic or simplified web-based PDF viewers might not execute the JavaScript at all, falling back to static views.




