converting text field to double

kidego32

New member
Local time
Today, 17:44
Joined
Aug 2, 2002
Messages
5
Hello,

I have a Text field in which I enter measurements such as :
32 1/2, 24 1/8, 15 3/4, etc.

I need to convert the value in the field to a double in order to do some calculations.

For example:

32 1/2 -> 32.5
24 1/8 -> 24.125

Thanks,

Julio
 
I solved the problem and I'm posting in case it's useful to someone else:

Here is the code I came up with:


Public Function FractionToDecimal(Number)
Dim NumberArray() As String
Dim FractionalArray() As String
Dim FirstPart As Double
Dim SecondPart As Double
Dim temp As Double


If (InStr(Number, "/")) Then

NumberArray = Split(Number)

temp = CDbl(NumberArray(0))

FractionalArray = Split(NumberArray(1), "/")
FirstPart = CDbl(FractionalArray(0))
SecondPart = CDbl(FractionalArray(1))

temp = temp + (FirstPart / SecondPart)

FractionToDecimal = temp
Else
FractionToDecimal = CDbl(Number)

End If


End Function
 
Try this:

Dim dblValue

dblValue=Eval(Replace("34 1/2"," ","+"))

The Replace Function will replace spaces with the Addition symbol.
34 1/2 -> 34 + 1/2


The Eval function will do the calculation
34 + 1/2 -> 34.5
 

Users who are viewing this thread

Back
Top Bottom