Software Archive
Read-only legacy content
17060 Discussions

reading integers as reals?

Intel_C_Intel
Employee
620 Views
I'm trying to read from a file various types of data. But, I really want all data to be read in as reals. But, when I try to read in an integer (say 1524), I get an error and the data is actually read in as 152.4. What can I do to force it to read it as 1524.0?
0 Kudos
2 Replies
TimP
Honored Contributor III
620 Views
Typically, this will work if you use formatted input, with formats such as F12.0, with the .0 being required. We may need a more specific example of your problem.
0 Kudos
Intel_C_Intel
Employee
620 Views
I do this all the time (or rather folks who use my program will leave out the decimal point for real inputs) and the code handles it just fine. Make certain that you are using an Fx.0 format for reading in the data where x is the field width that you are using. This allows the location of the decimal when it is read in to decide how many digits follow after the decimal point. If you don't use a decimal as input for say, 12, then the variable should take on the value of 12.0. I suspect that you are reading in the variable as an Fx.1 format, which will force something like 1234 to be read in as 123.4.

Tom
0 Kudos
Reply