-
2
- #1
bpeirson
Structural
- Apr 7, 2003
- 147
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.
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