PDF Editing Issues

How to Truncate PDF Calculations to Two Decimal Places

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 870 views

Question details

The user needs a calculated field in a PDF form to truncate to two decimal places (e.g., 3.236 to 3.23) rather than using the default rounding behavior (which makes it 3.24).

How to Truncate a PDF Calculation to Two Decimal Places
Product
PDF Editor
Device & OS
not provided
Scenario
Creating or modifying an interactive PDF form with calculated fields that require strict truncation for accurate financial or technical data.
Observed behavior
Applying a standard number format to the result field automatically rounds the number up or down depending on the third decimal digit, instead of simply dropping the extra digits.
Before you start

Ensure your PDF editor supports Form Editing and JavaScript execution, as you will need to apply a custom calculation script to override the default rounding rules.

Solution 1Recommended

Use a Custom JavaScript Calculation Script

Apply a mathematical script using Math.floor to manually drop extra decimal places before the PDF viewer applies its default formatting.

Standard PDF form fields store calculation results as 16-digit floating-point numbers. When you restrict the display to two decimal places via the Format tab, the software rounds the number automatically. To bypass this, you must intercept the value with a custom script and manually truncate it.

1
Open Field Properties

Enter Form Editing mode in your PDF application, right-click the target calculation field, and select 'Properties' from the context menu.

2
Access the Calculate Tab

Navigate to the 'Calculate' tab in the Properties dialog. Choose the 'Custom calculation script' option, and click the 'Edit' button to open the script editor.

3
Apply the Truncation Script

Write a script that calculates your value, multiplies it by 100, applies the Math.floor function, and divides by 100. For example: var raw = (your calculation); event.value = Math.floor(raw * 100) / 100;

4
Set the Display Format

Switch to the 'Format' tab, select the Number category, and set it to display exactly 2 decimal places. This ensures the truncated value is visually presented correctly.

Use a Custom JavaScript Calculation Script
Handling Negative Numbers: Math.floor works strictly by rounding down. For negative numbers (e.g., -3.236), Math.floor will yield -3.24. If your form processes negative values, write a script that converts the value to an absolute number first, applies the truncation, and then restores the negative sign.
Advanced PDF Form Editing

Easily Manage PDF Form Fields with WPS PDF

WPS Office features a robust PDF editor that simplifies creating, modifying, and filling interactive PDF forms, making complex field adjustments hassle-free.

  1. 1. Install WPS Office: Download and install the free WPS Office suite on your computer.
  2. 2. Open Your PDF Document: Launch WPS PDF and open the interactive form you need to edit.
  3. 3. Access Form Tools: Navigate to the 'Form' tab to interact with, manage, or modify form fields seamlessly.
  4. 4. Save and Export: Save your completed PDF document, ensuring all field data remains intact and formatted correctly.
Access comprehensive tools for filling and managing interactive PDF form fields.Fully compatible with Microsoft Office formats and standard Adobe PDF document structures.Lightweight, fast, and easy to navigate for everyday document processing needs.
QA img-9

Frequently Asked Questions

Why does my PDF field round numbers instead of truncating them?

By default, PDF viewers use standard floating-point formatting logic. When you restrict a field to a specific number of decimal places in the Format tab, the software automatically rounds to the nearest valid digit rather than simply dropping the excess decimals.

Can I use util.printf to truncate my calculation?

No, the util.printf function is strictly a formatting tool. If you use it to limit a number to two decimal places, it will round the value based on the decimal constraints, just like the standard format settings. You must use mathematical operations like Math.floor to strictly truncate the underlying value.

Does removing formatting show the true calculated value?

Yes. If you remove all formatting from the result field (setting the format category to 'None'), you will see the exact, unrounded 16-digit floating-point number that the software is holding in memory.