Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Distance conversion into feet and inches

1. ## Distance conversion into feet and inches

I have created a pdf fillable form with embedded (javascript)distance computations. I want to convert my output product, (example 137.42 ft) into feet - inches (example: 137'-5"). Is there a javascript to do this conversion?

Thanks!!!

• Code:
```<script type="text/javascript">
x = "137.42";  // x is a string value - must have a decimal point
if (!/\./.test(x)) {
x = x + ".00";  // if no decimal point append .00
}
y = x.split(".");
len = y[1].length;   // decimal places in initial value
p = Math.pow(10,len);
z = y[1]*12/p;
z = Math.round(z);  // if required. to round to nearest inch
k = y[0] + " feet " + z + " inches";
</script>```

BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

• I am still receiving an error message (missing } in XML expression). Can you look at my attachment and give me a suggestion?

Thanks!

• No, sorry. My paranoia prevents me from opening attachments posted by newcomers to the forum.

There is no missing } in the script I gave you.

• I understand. I will place my code first and error message below:

<script type="text/javascript">
x = "137.42";
if (!/\./.test(x))
{
x = x + ".00";
}
y = x.split(".");
len = y[1].length;
p = Math.pow(10,len);
z = y[1]*12/p;
z = Math.round(z);
k = y[0] + " feet " + z + " inches";
</script>

Error message I am receiving says:
missing } in XML expression
5: at line 6

• Well, it works just fine for me. (IE6)
I don't see any reason why it does not work with XML or another browser.

I would look for a non-matched { somewhere else. Or have you wrapped it in a function with no closing } tag?

• Still not working on my end. I am using Acrobat Professional 8.1.2. The script I posted above is a stand-alone script (no other associated coding with that particular cell field).

Am I missing something or is it possibly an Acrobat issue?

• Javascripts can only function as part of an .html file.

In other words, a javaScript can only be interpreted by a browser.

• I guess I'm out of luck unless someone else issues a different approach to my question. Thanks again for all your help!

• Originally Posted by Philip M
Javascripts can only function as part of an .html file.

In other words, a javaScript can only be interpreted by a browser.
i beg to differ Uses_outside_web_pages

anyways, perhaps this will get you started:

Code:
```function cu (n, s, e) { //convert units
LengthOb= ({inch:12, inches:12, foot:1, feet:1});
return (n* LengthOb[e]) / LengthOb[s];}

cu(0.42, "feet" , "inches")```

• Originally Posted by rnd me
i beg to differ
You tell me something, but Acrobat does not seem to want to run the simple script I provided. I have no idea why!

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•