Loss of numbers when dividing C ++ floats (Arduino)

I am trying to get a gps reading from a string in a float on my Arduino. The line everything handles all the digits just fine, but when I divide it to get a float, I lose 4 of my digits. Here is my code:

gpsStrings[0].replace(".", ""); lat = gpsRawData[0].toFloat(); lat = lat / 1000000.0; 

Using .toFloat for a string that still has a decimal point results in only two numbers after the decimal point.

Examples of numbers:

 42427898 :: 42.43 - what happens 42427898 :: 42.427898 - what I want to happen 
+6
source share
2 answers

It’s good that I was mistaken, the print function by default uses only two digits of accuracy. So I had to add the number of digits that I wanted to make.

 print(lat, 20); 

Gives 20 digits of accuracy on a serial monitor, where

 print(lat) 

gives only two.

+5
source
0
source

Source: https://habr.com/ru/post/923486/


All Articles