I'm working with a GPS locator, and I'm trying to get the GPS location data to look right. I can't seem to get the float values to store as a string with enough precision.I have the following code which is based on the "GPS" demo sketch from ADAFruit:
if (gps_success) {
Serial.print("GPS lat:");
Serial.println(latitude, 7);
Serial.print("GPS long:");
Serial.println(longitude, 7);
Serial.print("GPS altitude:");
Serial.println(altitude);
Serial.print("GPS speed KPH:");
Serial.println(speed_kph);
Serial.print("GPS speed MPH:");
speed_mph = speed_kph * 0.621371192;
Serial.println(speed_mph);
Serial.print("GPS heading:");
Serial.println(heading);
//join string
locationS = String(latitude,7)+ "," + String(longitude,7);
Serial.print("String output=");
Serial.println(locationS);
The problem is that I'm getting two different answers for "latitude" and "longitude." The output is as follows:
GPS lat:39.4110717
GPS long:-77.4046249
GPS altitude:103.80
GPS speed KPH:3.19
GPS speed MPH:1.98
GPS heading:259.40
String output=39.4110720,-77.4046250
If you notice, the "String output" line is rounded. For some reason, I can't get the number to go lower than 6 decimal places here, but I can get it to go down to 7 when I pipe the output to serial at the start of the submitted code.
I have tried using 'dtostrf,' but I get the same results. String(foo) is just shorter to write with the same output.
Why does Serial.println(foo,7) give me a different number than string(foo,7) and dtostrf(foo,13,7,*bar)?