Decimal to fraction
Decimal to fraction
Rate Decimal to fraction
(2(2 Vote))
Private Sub Command1_Click()
Dim upperPart As Long
Dim lowerPart As Long
Call Dec2Frac(Val(Text1.Text) / Val(Text2.Text), upperPart, lowerPart)
Text3.Text = upperPart & "/" & lowerPart
End Sub
Private Sub Dec2Frac(ByVal f As Double, upperPart As Long, lowerPart As Long)
Dim df As Double
upperPart = 1
lowerPart = 1
df = upperPart / lowerPart
While (df <> f)
If (df < f) Then
upperPart = upperPart + 1
Else
lowerPart = lowerPart + 1
upperPart = f * lowerPart
End If
df = upperPart / lowerPart
Wend
End Sub
Decimal to fraction Comments
No comments yet — be the first to post one!
Post a Comment