×
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

formating text strings

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

RE: formating text strings

Can you use a dimension and format the dimension style?

RE: formating text strings

(OP)
Thanks for reply

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

VBA is a full-featured programming language.  Multiply the decimal portion of your real number by 16 and take the integer portion of the result (or round it if you prefer).  Formatting is really simple.

David

RE: formating text strings

You can access the numbers in the attributes, they are stored as a string in the entity data. The lisp expression:
(rtos (atof NumberAsString)4 4))

will return a string of the number, rounded to the nearest 1/16.

RE: formating text strings

(OP)
For whatever reason I am having trouble figuring out how to
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

Here is one I found (I did not check it)...

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

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