Converting decimal feet to fractional feet and inches

Hello all,

new user here and I was wondering if I could get some help on a particular issue.

I am trying to have dynamo convert a decimal feet number to fraction feet and inches. the converted dimension should be formatted like xx’-yy". the idea is to then push this “converted” dimension back into Revit. also i need to have the precision of the “converted” dimension set at the nearest 1/2".

for example, I need to go from
4.56’ to 4’-6 3/4" (need to keep the “dash” as part of the dimension)

I did a search but have had no luck and unfortunately my programming skills are severely lacking.

any help would be appreciated.

You can try spring nodes’ Feet2Fraction node but you’ll need to tweak the fraction presentation a bit. Double click the custom node and change this line:

ft1s = __Apply(f1,ft1) + “'”;

to

ft1s = __Apply(f1,ft1) + “'-”;

basically just adding the extra dash that you need. Then change the content of

List.Cycle(2,7);

to

List.Cycle(2,2);

that way the node will round to the nearest 1/4th instead of the default nearest 1/128th.

2 Likes

Thank you Dimitar. I will give this a go once I get back in the office. I do have a question though. How does list.cycle(2,2) set a 1/4" precision?

It provides a list of the number 2 raised to the power of the desired input. Basically the same thing as using the Math.Pow node:

For some reason I felt like using List.Scan at the time when I originally made the node. the function later on determines which is the nearest fraction and uses that.

I See. Thank you for he clarification. The node now works as I want it to.

Thanks.

@Dimitar_Venkov
Hello
I have used the same node as I wanted to convert to feet and fractional inches, I am facing a problem that I hope you can help me solving, when the value is 1’ 3" the node shows the value as 1’ 2 2/2". , if the value is 1’ 1" it is displayed as 1’ 2/2", if the value is 3’ it is displayed as 2’ 11 2/2"
how can this be fixed
Thanks in advance

@Dalia

?

@kulkul
yes that what happens when I use it
the 1’ 2/2" is supposed to be 1’ 1", right?

Can we solve this please?

It would be nice if it can;

Take the number (x) and round down the number (y) then y gets to be feet value.
Then inches-wise, x-y*12. Then round up the value to be the inches.

Then it would be a home run for us.

I wish I knew c# to do this… =(

So, this is how far I got.

Now I need to figure out how to combine the two feet and inches together.
I did not bother providing fractions because building precision is typically 1".
Well, the next step can be getting the fractions out of the way but I would like to get the rounded versions to work properly first on our end.

  1. I need to get the 6 decimal digits out of the way first.
  2. Then, I need to combine feet and inches. (The calculation is complete as shown below.)

Please help.

Here is my attempt at converting… this will possibly give some insight to new users. It also formats the feet & inches as X’-X-X/X". It has some rounding and you can limit the fractional values. The feet2fraction node will definitely accomplish this much more gracefully. Enjoy!

DYN - General - Convert from Decimal FT to FT IN - Formatted.dyn (38.1 KB)