Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Decimal Numbers to Fractions

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access
View previous topic :: View next topic  
Author Message
mistux
Site Admin


Joined: 25 Jun 2004
Posts: 1042
Location: South Bend, Indiana USA

PostPosted: Mon Jan 28, 2008 10:17 am    Post subject: Decimal Numbers to Fractions Reply with quote

Code:
Function Num2Frac(ByVal x As Double) As String
      Dim Fixed As Double, Temp As String
        x = Abs(x)
        Fixed = Int(x)
        If Fixed > 0 Then
          Temp = CStr(Fixed)
        End If
       
        '**********
        'If Fixed = 0 Then   '**This failed
          'Temp = "0"
          'Num2Frac = Temp
          'Exit Function
        'End If
        '****************
       
        If x = 0 Then   '**This is so when they actually want a ZERO to print out.
          Temp = "0"
          Num2Frac = Temp
          Exit Function
        End If
       
        Select Case x - Fixed
           
          Case 0.1 To 0.145
            Temp = Temp + " 1/8"
          Case 0.145 To 0.182
            Temp = Temp + " 1/6"
          Case 0.182 To 0.225
            Temp = Temp + " 1/5"
          Case 0.225 To 0.29
            Temp = Temp + " 1/4"
          Case 0.29 To 0.35
            Temp = Temp + " 1/3"
          Case 0.35 To 0.3875
            Temp = Temp + " 3/8"
          Case 0.3875 To 0.45
            Temp = Temp + " 2/5"
          Case 0.45 To 0.55
            Temp = Temp + " 1/2"
          Case 0.55 To 0.6175
            Temp = Temp + " 3/5"
          Case 0.6175 To 0.64
            Temp = Temp + " 5/8"
          Case 0.64 To 0.7
            Temp = Temp + " 2/3"
          Case 0.7 To 0.775
            Temp = Temp + " 3/4"
          Case 0.775 To 0.8375
            Temp = Temp + " 4/5"
          Case 0.8735 To 0.91
            Temp = Temp + " 7/8"
          Case Is > 0.91
            Temp = CStr(Int(x) + 1)
        End Select
        Num2Frac = Temp
      End Function
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> Microsoft Access All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group