- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Tom

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page