john
10-01-1999, 07:02 PM
I am looking for code that will convert decimals to inches. Ex .125 = 1/8
Any help would be appreciated.
Any help would be appreciated.
|
View Full Version : Unit of Measure conversion john 10-01-1999, 07:02 PM I am looking for code that will convert decimals to inches. Ex .125 = 1/8 Any help would be appreciated. ahenduck 11-19-1999, 12:48 PM It sounds like a job for a very simple function. View the code below. Function DecimalFraction(num As Double, denominator As Long) As String Dim numerator As Long Dim tempstr As String Dim tempnum As Double If num >= 1 Then tempstr = Trim(str(Int(num))) tempnum = num - Int(num) Else tempstr = "" tempnum = num End If numerator = Int(denominator * tempnum) If numerator > 0 And tempstr = "" Then DecimalFraction = Trim(str(numerator)) + "/" + Trim(str(denominator)) ElseIf numerator = 0 And tempstr = "" Then DecimalFraction = "0" ElseIf numerator = 0 And tempstr <> "" Then DecimalFraction = tempstr ElseIf numerator > 0 And tempstr <> "" Then DecimalFraction = tempstr + " " + Trim(str(numerator)) + "/" + Trim(str(denominator)) End If End Function This code is not elegant, but will give a fraction based on the denominator given. |