Go Down

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


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:


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


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


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.


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;


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


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

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131