×
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

converting numbers to strings & strings to numbers

converting numbers to strings & strings to numbers

converting numbers to strings & strings to numbers

(OP)
I need to know how to convert character strings to numbers and also  how to convert numbers to strings.
Can anyone help?

RE: converting numbers to strings & strings to numbers

Dear Kknowle2

This answer was designed by Mr. Rafael Isassi who wrote this lines:

c     Just write your number to a string, or read your number from a string,
C     instead of to or from an I/O unit (the fortran I/O routines perform the
C     conversion). Example:

C     To convert to a string:
      character*10 string, format
      data format /'(F10.2)'/
      a=3.1416
      write(string,format)a
C     now print your string...
      print *,string

C     To convert a string to a floating point number:
      string='123456.789'
      read(string,*)b
C     now print your number...
      print *,b

      end

I hope this will be useful to you
Regards

RE: converting numbers to strings & strings to numbers

Here's another example of what KKnowle2 showed you in his reply:
It's in Fortran90/95,  however the Fortran77 code would be almost identical...
(   (10)  and  !  used for comments are not F77 compatible    )

Character(10) string
Real               x, y
x = 53.65                             ! assign an initial value to x, 53.65
Write( string, '(f10.2)' )  x      ! writes 53.65 into the string
Read( string, '(f10.0)' )  y      ! reads the value from string and assigns it to y
End                                     ! note the f10.0 format is nice... you don't have
                                          ! to know in advance where the decimal pt lies.
Dan   

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