How to Convert Decimal to Feet and Fractional Inches in PDF Forms
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.

- 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.
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.
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.
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.
In the Text Field Properties dialog box, click on the 'Format' tab. From the 'Select format category' dropdown menu, choose 'Custom'.
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\""; }
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.

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. Open PDF in WPS Office: Launch WPS Office and open your PDF form document.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to access the interactive field editing tools.
- 3. Edit Field Properties: Double-click your target text field to open its properties, where you can easily insert custom calculation and formatting scripts.

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.




