PDF Editing Issues

How to Truncate a Value Divided by 10 in Acrobat JavaScript

Maira MehtabMaira Mehtab Nov 5, 2026 868 views

Question details

The user needs a JavaScript method to strictly truncate, rather than round, a decimal result when dividing a PDF form field value by 10.

How to Truncate a Value Divided by 10 in Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating custom calculation scripts in a PDF form to manipulate number fields without automatic rounding.
Observed behavior
Using standard formatting functions like util.printf rounds the decimal value to a whole number instead of strictly truncating it.
Before you start

Ensure you have access to the 'Prepare Form' or form editing mode in your PDF software to safely edit the custom calculation scripts.

Solution 1Recommended

Use JavaScript Math.floor() or parseInt() for True Truncation

Use JavaScript's native mathematical functions to force truncation instead of rounding, ensuring the decimal part is completely discarded.

When working with PDF calculations, division often creates floating-point decimals. Functions like util.printf format the number by rounding it, which might not be desirable for strict truncations. Instead, convert the field to a strict Number type and apply Math.floor() for positive numbers or parseInt() for a universal truncation towards zero.

1
Open form properties

Open your PDF form in edit mode and double-click the target calculation field to open its Properties dialog.

2
Access custom calculation scripts

Navigate to the 'Calculate' tab, select 'Custom calculation script', and then click the 'Edit' button.

3
Apply truncation for positive values

For strictly positive values, enter the following script: event.value = Math.floor(Number(this.getField('Input').value) / 10);

4
Apply truncation toward zero

For values that might be negative and must truncate toward zero without rounding down, use: event.value = parseInt(Number(this.getField('Input').value) / 10, 10);

Use JavaScript Math.floor() or parseInt() for True Truncation
Data type safety: Using parseInt() with a radix of 10 safely ensures the decimal is dropped and explicitly converts the string field value into a numeric format.
Advanced PDF Form Management

Manage and Edit PDF Forms Seamlessly with WPS Office

WPS Office provides a highly capable PDF editor that allows you to view, fill, and manage complex PDF forms seamlessly. It is a highly efficient solution for handling daily document workflows.

  1. 1. Download WPS Office: Download and install WPS Office from the official website to access the comprehensive PDF suite.
  2. 2. Open your PDF form: Launch WPS PDF and open your interactive PDF document containing form fields and calculations.
  3. 3. Fill and calculate: Fill out your form fields effortlessly; WPS PDF fully supports interactive elements and displays calculation results accurately.
Fully compatible with standard PDF forms and Microsoft Word, Excel, and PowerPoint file formats.Lightweight installation and lightning-fast PDF rendering.Free access to essential PDF reading, filling, and annotation tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why does util.printf round my numbers instead of cutting them off?

The util.printf function in PDF JavaScript is designed to format numbers for display based on standard C-style formatting rules. When you specify zero decimal places (%.0f), it automatically rounds to the nearest integer rather than truncating.

What is the difference between Math.floor() and parseInt() in JavaScript?

Math.floor() always rounds down to the nearest integer, meaning -1.5 becomes -2. On the other hand, parseInt() simply strips the decimal portion completely, meaning -1.5 becomes -1, effectively truncating the number towards zero.

Why do I need to use Number() before dividing the field value?

Form fields often return their values as text strings. Wrapping the field value in Number() explicitly converts the string to a numeric format, preventing unexpected JavaScript concatenation or calculation errors during the division process.