- Home
·
- Math/Dates
·
- Changes a decimal number to a fraction up to x/64.
Changes a decimal number to a fraction up to x/64.
Changes a decimal number to a fraction up to x/64.
Rate Changes a decimal number to a fraction up to x/64.
(2(2 Vote))
Dim lngNumerator As Long
Dim lngWhole As Long
' Converts decimals to fractions. Returns max denominator of 64.
lngWhole = Fix(sglDecimal)
If lngWhole = 0 Then
DecimalToFraction = vbNullString
Else
DecimalToFraction = CStr(lngWhole) & " "
End If
lngNumerator = Abs((sglDecimal - lngWhole) / 0.015625)
Select Case lngNumerator
Case 0
DecimalToFraction = CStr(lngWhole)
Case 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62
lngNumerator = lngNumerator / 2
DecimalToFraction = DecimalToFraction & CStr(lngNumerator) & "/32"
Case 4, 12, 20, 28, 36, 44, 52, 60
lngNumerator = lngNumerator / 4
DecimalToFraction = DecimalToFraction & CStr(lngNumerator) & "/16"
Case 8, 24, 40, 56
lngNumerator = lngNumerator / 8
DecimalToFraction = DecimalToFraction & CStr(lngNumerator) & "/8"
Case 16, 48
lngNumerator = lngNumerator / 16
DecimalToFraction = DecimalToFraction & CStr(lngNumerator) & "/4"
Case 32
lngNumerator = lngNumerator / 32
DecimalToFraction = DecimalToFraction & CStr(lngNumerator) & "/2"
Case 64
DecimalToFraction = CStr(lngWhole + 1)
Case Else
DecimalToFraction = DecimalToFraction & CStr(lngNumerator) & "/64"
End Select
End Function
Changes a decimal number to a fraction up to x/64. Comments
No comments yet — be the first to post one!
Post a Comment