Free Lessons Courses Seminars TechHelp Fast Tips Templates Topic Index Forum ABCD

 Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon More... What's New? Popular Links ------------ Access Courses Access Index Access TechHelp Access Forum Access Troubleshooter Access Developer Network ------------ Excel Courses Excel Index ------------ Code Vault Testimonials Tip Jar Advice for Consultants

 Home > Courses > Access > Expert > X26 > More...X26 Outline < X25 | X27 >
 Back to Access Expert 26    Comments List
 Garry Frank        5 months ago
Is there a way to convert a fraction (i.e., Text string such as "1/5") to a number equivalent (0.20) in Access?  This works well in Excel, and if you have a database of recipes which normally would read "1/2" + the measurement, it is not easily read if you use the decimal equivalent, especially on a measurements that do not divide evenly into 1, such as 1/3 (0.3333...).  Yet, when creating a grocery list you need to know how much you need.
 5 months ago Can't remember if it's covered in Math in Fields.
 Adam Schwanz              5 months ago If not, you can use InStr to find the "/" then use something like Left to split the two sets of numbers and divide them.
 Kevin Robertson             5 months ago Are these the results you are looking for (see screenshot)?
 Kevin Robertson             5 months ago
 Kevin Robertson             5 months ago I updated the function to take into consideration values like '1 1/2', '5 2/4' and so on. Also, Null values are also covered and will return a zero (0). ```Public Function FracToDec(Fraction As Variant) As Double     Dim FracArray() As String, SpacePos As Long, WholeNum As Long, MyFrac As String          On Error GoTo ErrorHandler          WholeNum = 0     SpacePos = Nz(InStr(Fraction, " "), 0)          If SpacePos > 0 Then         WholeNum = Trim(Left(Fraction, SpacePos))         MyFrac = Trim(Right(Fraction, Len(Fraction) - SpacePos))     Else         MyFrac = Nz(Fraction, 0)     End If          FracArray = Split(MyFrac, "/")     If Not IsNull(Fraction) Then         FracToDec = WholeNum + (Round(Val(FracArray(0)) / Val(FracArray(1)), 2))     End If          Exit Function      ErrorHandler:     FracToDec = 0      End Function``` The screenshot below shows the results.
 Kevin Robertson             5 months ago
 Garry Frank        5 months ago Wow!  Thanks.  I appreciate the input.  Yes, the code is very helpful.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Expert 26.