# Taking GPS Coordinates from Serial Input

Hello Arduino Fellas.

I have a variable called arg, its a character. Which holds the value for Latitude in characters, "-84.1965068192297" typically in this format.

Whenever I do,

``````long a = atol(arg);
``````

I only get -84

And whenever I do

``````float a= atof(arg);
``````

I get like -84.196513455..

The numbers after some decimal points change. I want exactly what I entered. This is quite important, since the values are the GPS coordinates.

There's something wrong with atof() function.

Can somebody help me with this? Thanks.

``````long a = atol(arg);
``````

I only get -84 [/quote]

The long type does not have decimal places so that is correct.

[quote author=Mujtaba Chang link=topic=76419.msg577267#msg577267 date=1319354418] And whenever I do

``````float a= atof(arg);
``````

I get like -84.196513455..

The numbers after some decimal points change. I want exactly what I entered. This is quite important, since the values are the GPS coordinates. [/quote]

Floating point numbers are an approximation. Particularly on the Arduino where it uses 4-bytes floats. In those 4 bytes (32 bits) 23 are generally used for the mantissa. Now 2^23 is 8388608 which is a 7-digit number, so you wouldn't really expect the number to be accurate much past 7 digits.

You received: -84.1965068192297 You got: -84.196513455

That's accurate to 7 digits.

So is there a way out for this?

Depends what you want and mean by 'way out' You could use a 64 bit fixed point representation, say 10.54

By "way out", I meant is there any other way to get my REAL DATA into Arduino?

I just want GPS Coordinates from Google Maps into Arduino's Variables. The Coordinates from Google Maps are feed using Serial.

AWOL: You could use a 64 bit fixed point representation, say 10.54

I have no idea about 64 bit fixed point representation. Sorry for my ignorance towards C. I am a .NET programmer. Where I used Double to store these values.

[quote author=Mujtaba Chang link=topic=76419.msg577292#msg577292 date=1319358396] By "way out", I meant is there any other way to get my REAL DATA into Arduino? [/quote]

You have your real data into the Arduino. The question is what you are going to do with it.

Moving on from how floats are stored, what is your real problem?

Even GPS data is not totally accurate. There is an error factor of a few meters. What are you trying to do? What accuracy level is acceptable?

If you want to display the GPS data you can do that by displaying the string you received. If you are doing a calculation on it, what is its purpose? In what way would inaccuracy hurt that purpose?

I' m fairly sure you can write your own fixed point representation in whatever language you use under. NET

I just took Nick's consideration. 5 digits after decimal are more than enough for me for the accuracy.