How to Truncate a Value Divided by 10 in Acrobat JavaScript
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.

- 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.
Ensure you have access to the 'Prepare Form' or form editing mode in your PDF software to safely edit the custom calculation scripts.
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.
Open your PDF form in edit mode and double-click the target calculation field to open its Properties dialog.
Navigate to the 'Calculate' tab, select 'Custom calculation script', and then click the 'Edit' button.
For strictly positive values, enter the following script: event.value = Math.floor(Number(this.getField('Input').value) / 10);
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);

Round Values using util.printf (Alternative)
If you determine that the value should be rounded to the nearest whole number rather than strictly truncated, use the built-in PDF utility function.
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. Download WPS Office: Download and install WPS Office from the official website to access the comprehensive PDF suite.
- 2. Open your PDF form: Launch WPS PDF and open your interactive PDF document containing form fields and calculations.
- 3. Fill and calculate: Fill out your form fields effortlessly; WPS PDF fully supports interactive elements and displays calculation results accurately.

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.




