VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Decimal to fraction

by Waty Thierry (60 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Tue 13th April 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Decimal to fraction

Rate Decimal to fraction




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



Download this snippet    Add to My Saved Code

Decimal to fraction Comments

No comments have been posted about Decimal to fraction. Why not be the first to post a comment about Decimal to fraction.

Post your comment

Subject:
Message:
0/1000 characters