Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting numbers to strings & strings to numbers 1

Status
Not open for further replies.

kknowle2

Civil/Environmental
Jan 16, 2001
19
0
0
US
I need to know how to convert character strings to numbers and also how to convert numbers to strings.
Can anyone help?
 
Replies continue below

Recommended for you

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
 
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 :)
 
Status
Not open for further replies.
Back
Top