Skip to main content
Arduino

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Assigning float to 10 decimal place for longitude,latitude

I'm quite a novice in arduino programming. I am doing a small home project and I am using sim808 to obtain GPS data.

My question is quite simple but i can't find any solution online.

Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat, 10);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon, 10;

This code display Longitude and Latitude data on serial monitor to 10 decimal place perfectly.

But when after setting the Longitude and Latitude to float.When I use this code, I don't get a valid gps data.

Longitude = (sim808.GPSdata.lon, 10 );
Latitude = (sim808.GPSdata.lat, 10 );

Please help, Thanks.

(edited) I understand my error in coding for the above.

In fact, I am using a DF robot shield sim 808 for vehicle tracking. I am uploading my GPS data, longitude, latitude and speed to Ubidots. The only difficulty is in saving accurate data.

I am using this codes

Longitude = sim808.GPSdata.lon;
Latitude = sim808.GPSdata.lat;
Speedperkm = sim808.GPSdata.speed_kph;
client.add("Longitude", Longitude);
client.add("Latitude", Latitude);
client.add("Speed per Km", Speedperkm);

The code is working fine but only GPS data of 2 decimal place is being uploaded. If data of up to 6 decimal place is uploaded then the system will more accurate.

That my problem that I am trying to solve.

Answer*

Draft saved
Draft discarded
Cancel
4
  • Floats are always exact numbers, and 10.0 will always be 10, never 9.9999999999. You get rounding errors only when trying to represent as a float a number that cannot be exactly representable as a float. Commented Mar 23, 2017 at 9:52
  • @EdgarBonet not according technet.microsoft.com/en-us/library/ms187912(v=sql.105).aspx ... I mean a float as type (probably you mean a 'mathematical float' ? Commented Mar 23, 2017 at 9:58
  • 2
    Every float represents a number, in the mathematical sense of the word "number", i.e. defined with infinite precision. Most numbers are not representable as floats, and can thus only be approximated by floats. Every single integer in the range ±16777216 (and this include the number 10) is an exact float. Commented Mar 23, 2017 at 10:05
  • @EdgarBonet Yes you are completely right about the integers ... I will update the answer. Thanks. Commented Mar 23, 2017 at 10:34

default

AltStyle によって変換されたページ (->オリジナル) /