×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Imperial Fraction Function
2

Imperial Fraction Function

Imperial Fraction Function

2
(OP)
Here is a function I developed for Excel. I work in imperial units but many of my clients supply information in metric therefore there is a lot of conversion and rounding. This function has simplified the rounding and displaying of fractions.

The excel fractional formatting for sixteenths would never convert to eighths, quarters or halves. The formatting for fractions with 2 digits would give odd numbers such as 3/7 of 35/78. Although they were accurate no-one in the shop could find them on a tape measure.

No warranty is implied or expressed. Use and modify as you wish etc. etc.

Post back here if you need an explanation or clarification.


CODE

Public Function Imp_Frac(ByVal Dec_Arg) As String
Dim Num As Long, sixteenths As Integer

'Dim Num as Single will give values for large numbers
'     but the formatting goes exponetial at 10,000,000.
'Dim Num as Long will give values up to 2,147,483,647.9999
'     formatting will remain as expected.

Num = Fix(Dec_Arg)
sixteenths = Abs(Fix((Dec_Arg - Num) * 16))
Select Case sixteenths
    Case 1, 3, 5, 7, 9, 11, 13, 15
    Imp_Frac = Num & " " & sixteenths & "/16"
    Case 2, 6, 10, 14
    Imp_Frac = Num & " " & sixteenths / 2 & "/8"
    Case 4, 12
    Imp_Frac = Num & " " & sixteenths / 4 & "/4"
    Case 8
    Imp_Frac = Num & " 1/2"
    Case Else
    Imp_Frac = Num
    End Select
    
End Function

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources