c: string to float (only with Libc)? [duplicate]
Possible Duplicate:
string to float conversion?
how can i convert a string to float in c with only Libc?
You can use strtod or sscanf to do this.
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.
http://www.gnu.org/software/libc/manual/html_mono/libc.html#Parsing-of-Floats
particularly strtod
, strtof
correct link...
精彩评论