I want to store the coordinates with 6 decimals.
If 55.121421 is an example coordinate, you can't store all 8 significant digits in a [
float
](Floating-point arithmetic - Wikipedia). A float has about 7 significant digits.
NeoGPS is a library I wrote to have increased accuracy. It is smaller and faster than other libraries, and the example programs are structured correctly. It merges all information sent by the GPS device (i.e., all sentences) into a single fix structure. It can also be configured to parse only the fields and messages you really need, saving even more program space, RAM and time.
The coordinate type in NeoGPS retains 10 significant digits. It also has Distance, Bearing and Offset functions that provide more accurate results. Although a coordinate is internally stored as a long int, you can print it as if it were a floating-point value (see NMEAloc.ino).
Is possible limit the number of decimals to store? If I want for example only 6.
There are integers, like 55, that don't have any "decimals", and floating-point numbers, like 55.121421, that have "significant digits".
That's because a float has two internal parts: an exponent (like 5 for 25) and a mantissa. The floating point value is 2exponent * mantissa. So for 55.121421, the exponent would be 5 and the mantissa would be 1.722544:
2[sup]5[/sup] * 1.722544 =
32 * 1.722544 = 55.121421
The mantissa has only 7 digits.
But the number of "decimals" is not related to that. A floating point value could be 0.000000001234567. Although that's 15 decimals, it only has 7 significant digits, and would be represented by an exponent of -30 and a mantissa of 1.325606: 2-30 * 1.325606.
You usually store a value as an integer or a float (with all its "decimals"
), and print it later in the form you want to "see".
Cheers,
/dev