开发者

c: string to float (only with Libc)? [duplicate]

This question already has开发者_如何学Python answers here: Closed 12 years ago.

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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜