Fraction to decimal

  • Thread starter Thread starter Runutts
  • Start date Start date
R

Runutts

Guest
Wanted to take a text field with a fraction and do a comparison to a number field
 
You have to convert to a decimal first:

=Left([textboxname],InStr([textboxname],"/")-1)/Right([textboxname],Len([textboxname])-InStr([textboxname],"/"))
 
Thanks CPOD
that will work with just the fraction but, i can't seem to figure out how to do it with a hole number and a fraction like taken 6 3/4 and changing it to 6.75
 
Function Frac2Num(x)
'
' Parses a standard fraction of the form "a/b" or "a b/c" and returns a number.
' e.g. "2/5" or "3 1/2" are valid input.
'
Dim Temp As String, P As Integer, N As Double, Num As Double, Den As Double
If VarType(x) < 2 Or VarType(x) = 7 Then
Frac2Num = Null
ElseIf VarType(x) <> 8 Then
Frac2Num = x
Else
Temp = Trim$(x)
P = InStr(Temp, " ")
If P = 0 Then
If InStr(Temp, "/") = 0 Then
N = Val(Temp)
Else
N = 0
End If
Else
N = Val(left$(Temp, P - 1))
Temp = Mid$(Temp, P + 1)
End If
P = InStr(Temp, "/")
If P <> 0 Then
Num = Val(left$(Temp, P - 1))
Den = Val(Mid$(Temp, P + 1))
If Den <> 0 Then
N = N + Num / Den
End If
End If
Frac2Num = N
End If
End Function
 
Rich,That was just to sharp,
I will be reading your other posts.

Thanks again
 

Users who are viewing this thread

Back
Top Bottom