Need to store TinyGPSPlus location values in a variable

Hi, all. I am working with the TinyGPSPlus library, I am trying to save the location dd.mm values into a variable, but I'm trying to get a decimal value greater than two decimal places. I am following the same scheme as Serial.print():

Serial.print(gps.location.lat(), 6);
which produces the latitude to the 6th place beyond the decimal

Without the ", 6" I only receive the latitude to the second place beyond the variable.

However when I try this:

float gpslatWhole=(gps.location.lat(), 6);
Serial.println(gpslatWhole);

the output is:

6.00
6.00
6.00
6.00 ...

I've also tried this without the "float" and I get the same results.

How can I store the gps.location.lat() to a decimal value beyond the second into a variable?

Thank you,
Wayne

It's probably stored the way you want it, but if you Serial.print a float number, by default it will truncate to two decimals only. Try

Serial.println(gpslatWhole, 6);

Look up the C/C++ comma operator. "gpslatWhole" is set by the above line to 6.

The "6" in Serial.print() and related statements is a function argument to set the number of fractional digits to display.

In this line, gpslatWhole is set to the full precision of a float value returned by the function, which is 6-7 decimal digits, total.

float gpslatWhole = gps.location.lat();

2 Likes

Ahh! That makes sense, and it makes my project so much easier to accomplish. Thank you so much!!

Wayne

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.