Convert String to Float

Hi all! I am sending string from my phone to ESP32 over BLE with nRF Nordic App. The problem I have I think is all the functions in the code I have only read Float but String.

I tried using .toFloat() here

class MyCallbacks: public BLECharacteristicCallbacks {
  void onWrite(BLECharacteristic *pCharacteristic) {
    std::string rxValue = pCharacteristic->getValue();
    rxValue.toFloat();

but getting this error:
exit status 1
‘std::__cxx11::string {aka class std::__cxx11::basic_string}’ has no member named ‘toFloat’

Thanks in advance!

‘std::__cxx11::string {aka class std::__cxx11::basic_string}’ has no member named ‘toFloat’

seems the String class has no such function.

presumably you can use atof() using c_str() to convert a String to an ascii string

I would do this

String get_data;


 for (int i = 0; i < rxValue.length(); i++) {

          get_data += (char)rxValue[i];

        }

float xx = get_data.toFloat();   // OR THIS  float xx = get_data.toDouble();