More or less beginner with Arduino and the C language, I came across a problem where Arduino does not seem to keep enough decimals in a simple "multiplication / divider" operation.
My prolem is most simple : with the (GPS) string "4858.67068" I have to calculate the decimal degree of the Latitude by doing the following : 48 (first two caracteres) + 58.67068 (the remaining caracteres) / 60.
My Arduino (Uno) does only show at the end the value (float) of 48.98 while I was expecting many more decimals.
Something like 48,9778446666667
Any idea would be more than appreciated
Thanks for helping me out
Use Serial.print(value,N) to get N fractional decimal digits. The default for N is 2.
Note that the Uno uses single precision 32 bit floats, which limit the precision of a number to 6-7 digits total.
You can input a number like 48,9778446666667 but only the 97784 digits of the fraction will be meaningful.
Great !! I tied the option ",N" and indeed the decimals popped up.
Does that mean that is was just a question of formatting the output text butthe variable contained the right information ?
Again thanks for helping me out.
No. Your input has about 9 significant digits. The float datatype can only store about 6. (It is "about" because binary digits don't exactly match decimal digits. There is an exact binary precision.)
If you are okay with losing that little bit of precision then go ahead. Else use a library like TinyGPS.