formating text strings
formating text strings
(OP)
I would like to know how i can format a text string like
3.877 to be 3 7/8
looking to round to the nearest #/16
thanks in advance
3.877 to be 3 7/8
looking to round to the nearest #/16
thanks in advance





RE: formating text strings
RE: formating text strings
What i have is a master drawing that i have created.
The drawing is not to scale.
I went in and explode all the dimensions
then i created attributes for the text
so now i have attributes for all the dimensions that i can replace when values that i calc in my program
the drawing is not to scale
the part that i am missing now is being able to round the dimension from decimals to fractions...then all would be done.
is there nothing in VBA that will allow rounding of decimals to fractions ?
RE: formating text strings
David
RE: formating text strings
(rtos (atof NumberAsString)4 4))
will return a string of the number, rounded to the nearest 1/16.
RE: formating text strings
round numbers from a decmial format to fractions
Are there any vba scripts that will do this ?
I have several programs that i need to do this with.
guess i am brain dead on this one.....
RE: formating text strings
Function Dec2Fract(X As Single) As String
'------------------------------------------------------------------------------
' Returns a string of a number rounded to a whole and
'fraction in 16ths, 32nds, etc.
' Handles number > 1 and less than 0
' Use as follows:
' Label1.Caption = Dec2Fract(Val(Text1.Text))
' or Label1.Caption = Dec2Fract(Val(Label1.Caption)
'------------------------------------------------------------------------------
Dim F As String, Y As Single, Num As Integer, Den As Integer
Den = 16 'Denominator: can be set to 8, 16, 32, 64 etc
If X = 0 Then
Dec2Fract = "0"
Exit Function
Else
Y = Abs(X)
If Y > 1 Then Y = Y - Int(Y) ' get fractional part
Num = CInt(Den * Y)
If Num = Den Then
F = "1"
ElseIf Num = 0 Then
If Abs(X) < 1 Then F = "0" Else F = ""
Else
Do Until Num Mod 2 <> 0
Num = Num / 2
Den = Den / 2
Loop
F = LTrim$(Str$(Num)) + "/" + LTrim$(Str$(Den))
End If
If Abs(X) > 1 Then
If F <> "1" Then
F = Trim$(Str$(Fix(X))) + " " + F
Else
F = Trim$(Str$(CInt(X)))
End If
End If
If X < 0 And X > -1 Then F = "-" + F
Dec2Fract = F
End If
End Function
"Everybody is ignorant, only on different subjects." — Will Rogers