I use a u-blox gps with my arduino. I can successfully write out the value of a coordinate (lat, lng) like this: Serial.println (gps.location.lat(), 8); but when I try to store the value with all the decimals it returns 8.00 instead of the correct coordinate + all of the 8 decimals.

This is my code:

#include "TinyGPS++.h"
#include <SoftwareSerial.h>
SoftwareSerial gpsconnection (4,3);
TinyGPSPlus gps;

void setup()
 gpsconnection.begin (9600); 

void loop()
 while (gpsconnection.available())

 //this works and returns 8 decimals
 Serial.println (gps.location.lat(), 8);
 Serial.println (gps.location.lng(), 8);

 //but if i try to store it like this:
 double latcord = (gps.location.lat(), 8);
 double lngcord = (gps.location.lng(), 8);

 //it returns 8.00 on both the "latcord" and "lngcord" which is the wrong coordinate and also it doesnt return 8 decimals
 Serial.println (latcord);
 Serial.println (lngcord);

 //if i try to convert the value to a string and then back to a double like this:
 double lat = gps.location.lat();
 String msgLat =  String(lat, 8);

 double thelat = atof(msgLat.c_str());

 //with this i get the correct first two numbers out but only 2 decimals after, not 8 decimals as it should be.
 Serial.println (thelat);

  • Note, accuracy of floats and doubles is the same on Arduino: 25 bits max, or about 7.53 decimals Commented Jun 13, 2017 at 17:41

1 Answer 1


You forgot the , 8 from your println that specifies that it should print 8 decimal places. Instead you seem to have added it to the end of an assignment which makes absolutely no sense whatsoever.

double latcord = gps.location.lat();
double lngcord = gps.location.lng();

Serial.println(latcord, 8);
Serial.println(lngcord, 8);
  • ah ok so i cant store the value (with the 8 dec) straight to a double, i have to give the dec afterwards. got it! thanks Commented Jun 13, 2017 at 16:23
  • 2
    Floats and doubles don't have a fixed number of decimal places, that's not how they work.
    – Majenko
    Commented Jun 13, 2017 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.