# How to get first digit of a double precision number?

1. Nov 1, 2009

### aaron2

EDIT: Sorry, forgot to mention 'FORTRAN' in the subject line...

Hi, I'm new to fortran but I'm trying to generate the first 1476 terms of the fibonacci sequence, then examine the first digit of each term and store the number of 1s, 2s, 3s, ..., 9s that occur into an array. I have it to where it prints all of the terms to a text file, and I was going to try to read the first number from each new line.

However, it has been several hours and I have not been able to use this method, so I've decided to just get the first digit of the real number before actually writing it to the text document. Then, it's just a matter of reading the text document line by line without having to deal with all of the formatting business.

So, my question boils down to extracting the first digit of a double precision number (real*8) and storing it into an integer. Any ideas of how to do this?

2. Nov 1, 2009

### rcgldr

For the file, you could read in each line as a text string, then parse that string to find the "first" digit.

3. Nov 1, 2009

### aaron2

Yeah, I just started trying that. Currently I'm looking into how to find the first character of a string in fortran..

4. Nov 2, 2009

### silverfrost

I think you use the : operator:

print *,'first character is ' // ch(1:1)