当前位置: 技术问答>linux和unix
关于strtod的问题
来源: 互联网 发布时间:2016-04-05
本文导语: #include #include #include #include #include "string.h" int main() { long int i; char test1[80] = "19100.51 18688.35"; char test2[80] = "19100.51 0.04"; char test3[80] = "19100.51 0.04"; char test4[80] = "687.96 0.04"; char test5...
#include
#include
#include
#include
#include "string.h"
int main()
{
long int i;
char test1[80] = "19100.51 18688.35";
char test2[80] = "19100.51 0.04";
char test3[80] = "19100.51 0.04";
char test4[80] = "687.96 0.04";
char test5[80] = "687.96";
i = strtod(test1,0) -strtod(test1,0);
printf("test1 is %fn",strtod(test1,0));
printf("test2 is %fn",strtod(test2,0));
printf("test3 is %fn",strtod(test3,0));
printf("test4 is %fn",strtod(test4,0));
printf("test5 is %fn",strtod(test5,0));
printf("i is %d n",i);
return 0;
}
运行
test1 is nan
test2 is nan
test3 is nan
test4 is nan
test5 is nan
i is 2147483647
nan是打印的错误,但是2147483647就让我很纳闷了,不是应该为零吗?
#include
#include
#include
#include "string.h"
int main()
{
long int i;
char test1[80] = "19100.51 18688.35";
char test2[80] = "19100.51 0.04";
char test3[80] = "19100.51 0.04";
char test4[80] = "687.96 0.04";
char test5[80] = "687.96";
i = strtod(test1,0) -strtod(test1,0);
printf("test1 is %fn",strtod(test1,0));
printf("test2 is %fn",strtod(test2,0));
printf("test3 is %fn",strtod(test3,0));
printf("test4 is %fn",strtod(test4,0));
printf("test5 is %fn",strtod(test5,0));
printf("i is %d n",i);
return 0;
}
运行
test1 is nan
test2 is nan
test3 is nan
test4 is nan
test5 is nan
i is 2147483647
nan是打印的错误,但是2147483647就让我很纳闷了,不是应该为零吗?
|
double strtod ( const char * str, char ** endptr );
strtod的返回值是double。
long int i;
i = strtod(test1,0) -strtod(test1,0);
double类型是一个精度值,strtod(test1,0) -strtod(test1,0)的值不是0,而是一个满足一定精度的值,
比如 -0.00002
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!