Need help with type conversion from string (char array) to float using toFloat()

Hello good people :slight_smile:

I'm working on a project where I need to convert a char array representing a float that I receive from serial communication into a float. This is giving me a bit of trouble, here's what the code looks like at the moment:

//I am recewiving a char array that looks like this:

char myChar[] = {'1','2','.','4','5','\0'};
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

  delay(500);
  Serial.print("printing the char array ");
  Serial.print(myChar);                             //This works fine


  Serial.print('\n');
  Serial.print("Printing with toFloat()");
  Serial.print(myChar[6].toFloat());           

//This gives the error "request for member 'toFloat' in 'myChar[6]', which is of non-class type 'char'"
  
}

Any ideas how to convert a char array like myChar into a float?

The error message tells you that char is not a class, and don't have a method toFloat() (it's a member of String class).

By the way
myChar[6]

means the char at offset 6 of array myChar, and is out of bond, past the '\0'.

Use

Serial.print(strtod(myChar,NULL));

Awesome, just tested it out and it worked!
Thank you so much!