Go Down

### Topic: editing certain digits in a number (Read 740 times)previous topic - next topic

#### mjaredwilson

##### Mar 26, 2010, 11:06 pm
My GPS module is providing latitude and longitude in a form that needs to be changed.  It is giving Degrees, Minutes, and fractions of Minutes.  It is giving something similar to this:

3045.7834

I would like to change the Minutes into fractions of Degrees:

30.757834

Is there a simple way to alter the 3rd and 4th digits to put it into this form?

#### PaulS

#1
##### Mar 26, 2010, 11:53 pm
Is there a decimal point missing in the first example?

Are these strings?

If they are strings, you can use strtok to parse the string to get the degrees token, the minutes token and the minute fraction token. Then, use atoi to convert the tokens to numbers, and process the numbers as you wish.

#### mjaredwilson

#2
##### Mar 27, 2010, 05:22 pm
No, there is no decimal point missing.  I am using strtok to parse the whole nmea string as you helped me with before.  Since the latitude and longitude are strings before I convert them, I can just pull out the second two digits by using their index I believe.

tempminutes[0] = latitude[2];
tempminutes[1] = latitude[3];
latitude[2] = 0;
latitude[3] = 0;

tempminutes = tempminutes/60;
latitude = latitude + tempminutes;

#### mluckham

#3
##### Mar 29, 2010, 09:40 am
A minute is 1/60th of a degree, you can't just pull out selected digits - it needs to be scaled to get decimal degrees.

Minutes / 60

4226.5057,N,08152.7644,W

42 degrees N
26.5057 minutes / 60 = 0.44176 decimal degrees
42.44176 degrees

081 degrees W
52.7644 minutes / 60 = 0.87941 decimal degrees
081.87941 degrees

Go Up