I have a problem where I want to convert a string "32.89234" to float, and when I use string.toFloat() it only returns 32.89, is there a way that I can make it return all decimal places?
Thanks
I have a problem where I want to convert a string "32.89234" to float, and when I use string.toFloat() it only returns 32.89, is there a way that I can make it return all decimal places?
Thanks
How are you determining that .toFloat() only produces two decimal places? If you are printing the result, .print() defaults to two decimal places, if you want more you have to explicitly specify that:
Serial.print(floatNumber, 5); //print with 5 decimal places
Don't be too sure. The Arduino reference says,
"Note that "123.456" is approximated with 123.46"
Looks like .toFloat() and .toDouble() do not round at two decimal digits, at least on an UNO:
String f = "32.89234";
void setup()
{
Serial.begin(115200);
float ff = f.toFloat();
double fd = f.toDouble();
Serial.println(ff, 8);
Serial.println(fd, 8);
}
void loop() {}
Results:
32.89234161
32.89234161
That's a relief if you are using the String class.