设为首页 加入收藏

TOP

C语言中如何将字符串转换成float和double类型
2014-11-24 02:01:49 来源: 作者: 【 】 浏览:1
Tags:言中 如何 字符串 换成 float double 类型

C语言中如何将字符串转换成float和double类型


先贴上可编译运行的源代码:


file: a.cpp


#include


#include
int main ()
{
char szOrbits[] ="365.24";
char* pEnd;
float f1;
f1 = strtof (szOrbits, &pEnd);
printf("%f\n",f1);
return 0;
}


执行结果:


[tuxedo@imorcl yali_test]$ g++ a.cpp -o aaa
[tuxedo@imorcl yali_test]$ ./aaa
365.239990



man参考手册:在linux上 man strtod就能显示


NAME
strtod, strtof, strtold - convert ASCII string to floating point number


SYNOPSIS
#include


double strtod(const char *nptr, char **endptr);


#define _XOPEN_SOURCE=600 /* or #define _ISOC99_SOURCE */
#include


float strtof(const char *nptr, char **endptr);
long double strtold(const char *nptr, char **endptr);


DESCRIPTION
The strtod(), strtof(), and strtold() functions convert the initial portion of the string pointed to by nptr to double, float, and
long double representation, respectively.


。。。


推荐阅读


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux内核--内核数据类型 下一篇选择正确的 JSR-352 (Java批处理..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: