FLOAT VALUE STORING IN MEMORY-ARDUINO

Discussion in 'Programmer's Corner' started by AJIN NADH, Sep 23, 2015.

  1. AJIN NADH

    Thread Starter Member

    Dec 18, 2014
    79
    4
    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
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,140
    1,790
  3. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Try scanf function. That is in C, no idea how this works in arduino.
     
  4. dannyf

    Well-Known Member

    Sep 13, 2015
    1,796
    360
    The easiest but least efficient approach is to use scanf/printf.
     
  5. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,804
    833
    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.

    Code (C):
    1. void setup() {
    2.  
    3.   String myString="123.5";
    4.   float myNumber=0;
    5.  
    6.   myNumber=myString.toFloat();
    7. }
    8.  
    9. void loop() {
    10. }
    Here is a link to the Arduino reference pages, describing the String class.

    I personally think this is easier than scanf/printf...
     
  6. AJIN NADH

    Thread Starter Member

    Dec 18, 2014
    79
    4
    Thanks for the support,,,,
     
Loading...