Cast String to float number more than 2 decimal digit after the point

//I checked toFloat() return number like 35.44 I want more than 2 digit after the point

for(int i=0;i<nmea[1].length();i++){
if(nmea[1].substring(i,i+1).equals(".")){
lon=nmea[1].substring(0,i-2).toFloat();
stringPlace=i+1;
lon+=nmea[1].substring(i-2).toFloat()/60.0;
}}

//and atof() function does not work as I was waiting

for(int i=0;i<nmea[3].length();i++){
if(nmea[3].substring(i,i+1).equals(".")){
lat=atof(nmea[3].substring(0,i-2).c_str());
stringPlace=i+1;
char carray[6];
nmea[3].substring(i-2).toCharArray(carray, sizeof(carray));
lat=atof(carray);
Serial.println(lat);
}}

So print more than two.

Please remember to use code tags when posting ALL of your code

Try this:

thanks solved, I should to write the number after the point to see it :slight_smile:

By default, .print() and .println() show two digits after the decimal point. You can specify how many to print:
Serial.print(123.456, 17);
Note: Only the first 6 significant digits can be expected to be correct. Even though you can print 123.456 with 17 digits after the decimal point, you can't expect anything past three decimal digits to be correct. The three digits BEFORE the decimal are also 'significant digits'.

thanks you to explain it

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.