Here is one I found (I did not check it)...
Function Dec2Fract(X As Single) As String
'------------------------------------------------------------------------------
' Returns a string of a number rounded to a whole and
'fraction in 16ths, 32nds, etc.
' Handles number > 1 and less than 0
' Use as follows:
' Label1.Caption = Dec2Fract(Val(Text1.Text))
' or Label1.Caption = Dec2Fract(Val(Label1.Caption)
'------------------------------------------------------------------------------
Dim F As String, Y As Single, Num As Integer, Den As Integer
Den = 16 'Denominator: can be set to 8, 16, 32, 64 etc
If X = 0 Then
Dec2Fract = "0"
Exit Function
Else
Y = Abs(X)
If Y > 1 Then Y = Y - Int(Y) ' get fractional part
Num = CInt(Den * Y)
If Num = Den Then
F = "1"
ElseIf Num = 0 Then
If Abs(X) < 1 Then F = "0" Else F = ""
Else
Do Until Num Mod 2 <> 0
Num = Num / 2
Den = Den / 2
Loop
F = LTrim$(Str$(Num)) + "/" + LTrim$(Str$(Den))
End If
If Abs(X) > 1 Then
If F <> "1" Then
F = Trim$(Str$(Fix(X))) + " " + F
Else
F = Trim$(Str$(CInt(X)))
End If
End If
If X < 0 And X > -1 Then F = "-" + F
Dec2Fract = F
End If
End Function
"Everybody is ignorant, only on different subjects." — Will Rogers