作者:蕊儿巧乐-滋 | 来源:互联网 | 2023-05-30 12:13
C库函数 double atof(const char *str)转换的字符串参数str一个浮点数(double类型)。 声明以下是atof() 函数的声明。double atof(constchar
C库函数 double atof(const char *str)转换的字符串参数str一个浮点数(double类型)。
声明
以下是atof() 函数的声明。
double atof(constchar*str)
参数
返回值
这个函数返回转换后的浮点数作为一个double值。如果没有有效的转换可以执行,它返回零(0.0)。
例子
下面的例子显示atof() 函数的用法。
#include#include#includeint main(){float val;char str[20];
strcpy(str,"98993489");
val = atof(str);
printf("String value = %s, Float value = %f
", str, val);
strcpy(str,"xyhtml5.com");
val = atof(str);
printf("String value = %s, Float value = %f
", str, val);return(0);}
让我们编译和运行上面的程序,这将产生以下结果:
String value = 98993489, Float value = 98993488.000000
String value = xyhtml5.com, Float value = 0.000000