C语言中将字符串转化为浮点数
strtod() 函数的声明
double strtod(const char *str, char **endptr)
参数
str – 要转换为双精度浮点数的字符串。
endptr – 对类型为 char* 的对象的引用,其值由函数设置为 str 中数值后的下一个字符。
包含的头文件
#include "string.h"
变量初始化
double num=0;char str[100]={"1.1TEST"};char *ptr;
运行
num = strtod(str,&ptr);//将字符串转化为浮点数printf("数字(double)是 %f\n", num);printf("字符串部分是 |%s|", ptr);