FLOAT VALUE STORING IN MEMORY-ARDUINO

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
Hi,
I want to store and read back the float value , as read as the string, anything is to convert the string to float value...
pls help.....


Regards,
Ajin Nadh.v.a
 

djsfantasi

Joined Apr 11, 2010
9,163
Do you mean a variable of type String or of type char array? If your number is stored in a String object (or variable), it has a function/method associated with it called toFloat(). Hence, conversion is one line of code.

C:
void setup() {

  String myString="123.5";
  float myNumber=0;

  myNumber=myString.toFloat();
}

void loop() {
}
Here is a link to the Arduino reference pages, describing the String class.

I personally think this is easier than scanf/printf...
 

Thread Starter

AJIN NADH

Joined Dec 18, 2014
84
Do you mean a variable of type String or of type char array? If your number is stored in a String object (or variable), it has a function/method associated with it called toFloat(). Hence, conversion is one line of code.

C:
void setup() {

  String myString="123.5";
  float myNumber=0;

  myNumber=myString.toFloat();
}

void loop() {
}
Here is a link to the Arduino reference pages, describing the String class.

I personally think this is easier than scanf/printf...
Thanks for the support,,,,
 
Top