I am trying to parse a string sent to my arduino uno using serial communication into a float. I want to use these floats to set an RGB LED's color. My issue is, it will only read the first 2 digits. Sorta. Say I entered 100. It will only come out to 10.00. If it's 231, it will come out to 23.00. The weird thing is, if I put 32.43, it will come out 32.4300. I have no idea why it does this. Here is my code:
float led1Color[3];
...
for (int i = 0; i < 3; i++) {
int index = content.indexOf(",");
content = content.substring(index + 1); //removes additional text in front of numbers
led1Color[i] = atof(content.substring(0, index).c_str());
Serial.println(led1Color[i], 4);
}
Now lets say I sent the following: "RGBLED,43.61,52,231". First, the RGBLED is removed. Then, the 3 values the console shows me are as followed:
43.6100 52.0000 23.0000
Obviously the issue here is I need the value 231, not 23.0000. I've never actually programmed in C/C++ before, so is there something I'm missing? Why is a three digit number being converted into a two digit number?