strtod

王朝百科·作者佚名  2010-04-29
窄屏简体版  字體: |||超大  

strtod(将字符串转换成浮点数)

相关函数

atoi,atol,strtod,strtol,strtoul

表头文件

#include<stdlib.h>

定义函数

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

函数说明

strtod()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,到出现非数字或字符串结束时('')才结束转换,并将结果返回。若endptr不为NULL,则会将遇到不合条件而终止的nptr中的字符指针由endptr传回。参数nptr字符串可包含正负号、小数点或E(e)来表示指数部分。如123.456或123e-2。

返回值

返回转换后的浮点型数。

附加说明

参考atof()。

范例

#include<stdlib.h>

main()

{

char *endptr;

char a[]="12345.6789";

char b[]="1234.567qwer";

char c[]="-232.23e4";

printf("a=%lf

",strtod(a,NULL));

printf("b=%lf

",strtod(b,&endptr));

printf("endptr=%s

",endptr);

printf("c=%lf

",strtod(c,NULL));

}

执行

a=12345.678900

b=1234.567000

endptr=qwer

c=-2322300.000000

linux c function()中关于strtod的范例有误

扩展阅读中关于strtod的范例有误。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航