PDF Editing Issues

How to Convert Decimal to Feet and Fractional Inches in PDF Forms

John WilsonJohn Wilson Nov 24, 2026 870 views

Question details

The user needs to convert calculated decimal numbers into readable architectural units consisting of feet, inches, and fractions within a PDF form field.

How to Convert Decimal to Feet and Fractional Inches in PDF Forms
Product
PDF Forms
Device & OS
not provided
Scenario
Designing an interactive PDF form for architectural or engineering purposes where calculations result in decimals, but the end-user requires standard US customary length formats.
Observed behavior
The calculated fields display raw decimal values instead of formatting them into standard feet and fractional inches.
Before you start

Ensure you have access to a robust PDF editor that supports form field properties and custom JavaScript execution, such as WPS Office PDF or Adobe Acrobat.

Solution 1Recommended

Apply Custom JavaScript Formatting to Form Fields

Use a custom JavaScript script in the target text field's format properties to process the decimal value and output formatted text.

Because converting decimals to clean fractions can involve irrational numbers, standard formatting options will not suffice. This custom script divides the raw value into whole feet and inches, then rounds the remaining decimal to the nearest 16th-inch fraction for architectural standards.

1
Access Field Properties

Open your PDF form in edit mode. Right-click the text field where you want the feet and inches to appear, and select 'Properties' from the context menu.

2
Navigate to Custom Format

In the Text Field Properties dialog box, click on the 'Format' tab. From the 'Select format category' dropdown menu, choose 'Custom'.

3
Enter the JavaScript Code

Click the 'Edit' button next to the Custom Format Script window and paste the following code: var val = Number(event.value); if (val > 0) { var feet = Math.floor(val / 12); var inchesDecimal = val % 12; var inches = Math.floor(inchesDecimal); var fractionDecimal = inchesDecimal - inches; var sixteenths = Math.round(fractionDecimal * 16); event.value = feet + "' " + inches + " " + sixteenths + "/16\""; }

4
Save and Test

Click 'OK' to save the script, then close the properties window. Switch to Preview or Hand mode and enter a decimal calculation to verify it correctly converts to feet, inches, and fractions.

Apply Custom JavaScript Formatting to Form Fields
Adjusting Fraction Precision: The provided script rounds fractions to the nearest 16th of an inch. If your project requires finer granularity, such as 32nds or 64ths, simply change the multiplier in the script from 16 to the desired denominator.
Advanced PDF Form Solution

Create and Edit Smart PDF Forms with WPS Office

WPS Office offers a comprehensive suite of PDF tools, allowing you to easily design interactive forms, apply custom JavaScript calculations, and ensure seamless formatting across devices.

  1. 1. Open PDF in WPS Office: Launch WPS Office and open your PDF form document.
  2. 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access the interactive field editing tools.
  3. 3. Edit Field Properties: Double-click your target text field to open its properties, where you can easily insert custom calculation and formatting scripts.
Easily create interactive text fields, checkboxes, and dropdowns.Support for custom JavaScript execution for advanced formatting and calculations.Fully compatible with standard Microsoft Office and Adobe PDF formats.Lightweight architecture for fast loading and smooth editing.
microsoft office alternative - wps office

Frequently Asked Questions

Can I format the decimals to different fractional units like 1/8 instead of 1/16?

Yes. By adjusting the multiplier in the JavaScript code, you can change the precision. Simply replace the number 16 with 8 (for eighths) or 32 (for thirty-seconds) depending on your required architectural measurements.

Is JavaScript the only way to format numbers as feet and inches in PDFs?

Yes. Built-in PDF formatting options only cover standard numbering systems like percentages, currencies, dates, and simple decimals. For specialized architectural formats that combine multiple units and fractions, custom JavaScript is mandatory.

Why does the fraction sometimes display as 16/16 instead of rounding up the inches?

This happens when the remaining decimal is extremely close to a whole number and rounds up to the denominator. To resolve this, you can add an 'if' statement to your script that checks if the fraction equals 16/16, and if so, sets the fraction to 0 and adds 1 to the inches variable.

Will these custom scripts work when the PDF is viewed on a mobile device?

It depends on the specific mobile PDF viewer being used. While powerful desktop applications like WPS Office and Adobe Acrobat fully support JavaScript formatting, many default mobile PDF viewers have restricted script execution and may only display the raw decimal value.