- Home
·
- Math/Dates
·
- Converts fractions to decimals (x/2, x/4, x/8, x/16, x/32, x/64). Modifications can be made for oth
Converts fractions to decimals (x/2, x/4, x/8, x/16, x/32, x/64). Modifications can be made for oth
Converts fractions to decimals (x/2, x/4, x/8, x/16, x/32, x/64). Modifications can be made for other denominators.
Rate Converts fractions to decimals (x/2, x/4, x/8, x/16, x/32, x/64). Modifications can be made for oth
(2(2 Vote))
Dim intCount As Integer
Dim lngDenominator As Long
Dim lngNumerator As Long
Dim lngRetCode As Long
Dim lngWhole As Long
Dim strTemp As String
FractionToDecimal = 0#
strFraction = Trim$(strFraction)
If strFraction > vbNullString Then
For intCount = 1 To Len(strFraction)
Select Case Asc(Mid$(strFraction, intCount, 1))
Case 32, 45, 47 To 58 ' space, minus, divide, and 0 to 9
Case Else
If IsNumeric(strFraction) Then
FractionToDecimal = CSng(strFraction)
End If
Exit Function
End Select
Next intCount
lngRetCode = InStr(strFraction, "/")
If lngRetCode > 0 Then
lngRetCode = InStr(strFraction, " ")
If lngRetCode > 0 Then
lngWhole = CLng(Left$(strFraction, lngRetCode - 1))
strTemp = Right$(strFraction, Len(strFraction) - lngRetCode)
Else
lngWhole = 0
strTemp = strFraction
End If
lngRetCode = InStr(strTemp, "/")
If lngRetCode > 0 Then
lngNumerator = CLng(Left$(strTemp, lngRetCode - 1))
lngDenominator = CLng(Right$(strTemp, Len(strTemp) - lngRetCode))
If lngDenominator <> 0 Then
If lngWhole < 0 Then
FractionToDecimal = lngWhole - (lngNumerator / lngDenominator)
Else
FractionToDecimal = lngWhole + (lngNumerator / lngDenominator)
End If
End If
End If
Else
FractionToDecimal = CSng(strFraction)
End If
End If
End Function
Converts fractions to decimals (x/2, x/4, x/8, x/16, x/32, x/64). Modifications can be made for oth Comments
No comments yet — be the first to post one!
Post a Comment