# String to floating point (7 sig-fig precision)

Hello everyone, I have the following string: "4238.27191"
I then convert it to a character array which reads: "4238.27191"
Now when I convert to a float, I read: "4238.27"
When I divide that number by 100 (to move the decimal), I read: "42.38"

I need to retain at least seven digits, why am I only outputting four? Double float did not work..
I can live with the standard float output, but why does the division operator output only five characters? four digits of precision?
Is there any way to move the decimal without loosing so much precision?

Maybe I am way off of the ball in my code..

``````  String GPSLatInA = "";      // Current GPS Latitude
String GPSLonInA = "";      // Current GPS Longitude
char GPSLatInB;      // Current GPS Latitude
char GPSLonInB;      // Current GPS Longitude
float GPSLatInC;      // Current GPS Latitude
float GPSLonInC;      // Current GPS Longitude

.
.
.

case 3:
GPSLatInA = ( GPSBuffer.substring(0,DelimiterPosition));
GPSLatInA.toCharArray(GPSLatInB, GPSLatInA.length()+1);
GPSLatInC = atof(GPSLatInB);
GPSLatInC = (GPSLatInC/(100.000));
break;
case 5:
GPSLonInA = ( GPSBuffer.substring(0,DelimiterPosition));
GPSLonInA.toCharArray(GPSLonInB, GPSLonInA.length()+1);
GPSLonInC = atof(GPSLonInB);
GPSLonInC = (GPSLonInC/(100.000));
break;
``````

Do you guys know of any clever stdlib.h functions that will allow me to retain my original string as integers?

Thanks!

for the float try Serial.print(f, 4); // that's the number of decimals.

Haha, this is incredible. You've just solved my issue.

I can't express enough how much I appreciate the help!
Many thanks-

I need to retain at least seven digits

You realize, I hope, that the 7 significant digits refers to ALL the digits, not 7 after the decimal place.

4238.27191

The 7 is the last precise digit. The one after it may or may not be precise. The 91 part is noise.

Printing 4 digits after the decimal point, after printing 4 before, implies 8 digits of precision. At least one, and possibly 2, of the digits after the decimal point are noise.

Yes, I know what I said.
4238.271 is what I am after (and have achieved thanks to robtillaart), the 91 is estimated by the IC chip.

You might try to convert the numbers to unsigned long - these have 9 digits of precision - and when you print you should add the decimal . yourself

``````print (longValue/1000);
print ('.');
print(longValue%1000);
``````