 # How to convert Decimal Feet to Fractional Feet and Inches

Here’s a new script that converts decimal feet to a fraction:

The precision input and a few other shortcuts allow the script to run quickly.
0" and dash symbols are controllable as well.

The design script is below:

//Convert Decimal Feet to Imperial Fraction
feet = Math.Floor(feetDec);
inch = Math.Floor(inchDec);
feetDec = Math.Round(numberprec12,0)/(prec12);
inchDec = Math.Round((feetDec-feet)12,8);
fracDec = inchDec-inch;
depthBool = prec==[1,2,4,8,16,32,64,128,256];
index = List.IndexOf(depthBool, true);
power = Math.Pow(2, (0…#index+1…1));
root = List.Transpose((fracDec
prec)/power@L1<1>);
n = List.MinimumItem(Math.Round(root)==root? root: root+10000);
ds = “/”+List.Reverse(power)+"";
dInd = List.FirstIndexOf(root@L2<1>, n@L1<1>);
d = List.GetItemAtIndex(ds, dInd);
fracStr = String.StartsWith(n+d, “0”, false)? “”: " “+n+d;
frac = String.Replace(fracStr, “.000000”, “”);
end0 = feet+”’"+"-"+inch+frac+""";
endD = String.Replace(end0, “-0"”, show0? “-0"”: “”);
endFT = String.Replace(endD, “-”, dash);
endIN = (feet
12)+inch+frac+""";

Enjoy!

Converting decimal feet to fractional feet and inches

2 Likes

This is great. There are also unit conversion and formatting nodes in archi-lab.net package:

Cheers!

-K

4 Likes

Amazing.
The node that I used to use from Springs was my go to for this kind of task. But when I ran the node on a list of about 2,000 items (like a wall schedule) it would take about a minute to finish. So when I had built a code block that could do the same list in just over a second, I thought I had the cat in the bag. On the other hand, your nodes do it instantly. Way more options too!

Precision is an easy adjustment, but Is there a better option for inches?

You can get decimal/fractional inches by defining what formatting you want for your units:

3 Likes