Cant convert sring to float.

I am trying to convert a string constructed by the textstring library into a float.

String xstr = String(10);
...
         float xwantedpos = float(xstr);
         Serial.println(xwantedpos);
...

I get this error message: error: invalid cast from type 'String' to type 'float'

how can I convert these types of strings to floats/doubles.

You can use the function atof(), like this:

  char* strVal = "3.1415";
  float fVal = atof(strVal);