Pages: [1]   Go Down
Author Topic: editing certain digits in a number  (Read 405 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50111
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
Logged

Ontario, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: