How to convert decimal string to float?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Shmoo

    How to convert decimal string to float?

    I have a string representing a decimal value like 123.456 (or -90.4005 etc.) and I need to represent it by a float datatype (4 bytes). What is the math used to do so? When I Google all I can find are calculators that do it for you but I have to implement it on a microcontroller . Thanks.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Are you using C or C++?

    If it's C, then call atof().

    If it's C++, insert your string into a stringstream and extract it to a double.

    Comment

    Working...