-3

Possible Duplicate:
string to float conversion?

how can i convert a string to float in c with only Libc?

1
  • Please have a look at: man sscanf Commented Jan 3, 2011 at 16:45

3 Answers 3

0

You can use strtod or sscanf to do this.

Sign up to request clarification or add additional context in comments.

Comments

0
char *float_str = "10.5";
double d = atof(float_str);

or

char *float_str = "10.5";
double d = strtod(float_str, (char **) NULL);

(The second form is recommended for newer code, as atof is deprecated in favor of strtod.)

It's in the stdlib.h header.

1 Comment

hmm.. not recommended for new code... strtod/strtof is the way forward..
0

http://www.gnu.org/software/libc/manual/html_mono/libc.html#Parsing-of-Floats

particularly strtod, strtof

correct link...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.