Convert from decimal to fractional inches (string)


Hi there, just wanted to share this piece of code. As I need to do this a lot it might be useful to someone who is not familiar with coding.
At first, I was using the spring nodes one that is great but I had to add a lot of nodes to it to get to this.
So this simple python node will give you a string with your fractional inches round down to a predefined approximation.

# Enable Python support and load DesignScript library
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
# Place your code below this line
# Data imput definitions
n=IN[0] #Numbers to be converted
app=IN[1] #Approximation i.E = 1/8" = 0.125 decimal. **** In Decimal ****
#The result array
#If approximation is not defined, default it to 0.125 [1/8"]
if not app:
	app = 0.125
#Check to see if your imput have a single number or a list
if type(n) is float:

#If it is a single number
	for e in n:
		b = e - int(e)
		length = len(str(e))
		round(b, 3)
		if b < app:
			if (b%app) > 0:
				r.append(str(int(e))+" "+d)	

# Assign your output to the OUT variable.
OUT = r