Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

arduino

I am trying to get a gps reading from a string to a float on my Arduino. The string has all handles all of 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 on a string that still has the decimal point in it results in the same thing, only two numbers after the decimal point.

Example numbers:

42427898 :: 42.43 - what happens
42427898 :: 42.427898 - what I want to happen
like image 886
Steven Avatar asked Aug 22 '12 14:08

Steven


1 Answers

Alright I was wrong, the default print function only uses two digits of precision. So I had to add how many digits I wanted to the statement.

print(lat, 20);

Will give 20 digits of precision on the serial monitor where

print(lat)

only gives two.

like image 103
Steven Avatar answered Sep 27 '22 17:09

Steven