还是数据类型转换 如何将字符串转换成 双精度?waiting on line 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我想把 如果 有 a='1.2453',b='32'我想实现 a+b 的结果为 33.2453 怎么办呢? 有个函数,好像atoul还是什么,可以用,忘了,你查查!呵呵 double strtod( const char *nptr, char **endptr );double wcstod( const wchar_t *nptr, wchar_t **endptr );Example/* STRTOD.C: This program uses strtod to convert a * string to a double-precision value; strtol to * convert a string to long integer values; and strtoul * to convert a string to unsigned long-integer values. */#include <stdlib.h>#include <stdio.h>void main( void ){ char *string, *stopstring; double x; long l; int base; unsigned long ul; string = "3.1415926This stopped it"; x = strtod( string, &stopstring ); printf( "string = %s\n", string ); printf(" strtod = %f\n", x ); printf(" Stopped scan at: %s\n\n", stopstring ); string = "-10110134932This stopped it"; l = strtol( string, &stopstring, 10 ); printf( "string = %s", string ); printf(" strtol = %ld", l ); printf(" Stopped scan at: %s", stopstring ); string = "10110134932"; printf( "string = %s\n", string ); /* Convert string using base 2, 4, and 8: */ for( base = 2; base <= 8; base *= 2 ) { /* Convert the string: */ ul = strtoul( string, &stopstring, base ); printf( " strtol = %ld (base %d)\n", ul, base ); printf( " Stopped scan at: %s\n", stopstring ); }}Outputstring = 3.1415926This stopped it strtod = 3.141593 Stopped scan at: This stopped itstring = -10110134932This stopped it strtol = -2147483647 Stopped scan at: This stopped itstring = 10110134932 strtol = 45 (base 2) Stopped scan at: 34932 strtol = 4423 (base 4) Stopped scan at: 4932 strtol = 2134108 (base 8) Stopped scan at: 932 sscanf(str, "%lf", &doubleValue) 关于dll远程注入的问题 用memcpy函数时遇到的一个极诡异的现象,高人解释下 怎么没人理我?*.wrf是什么格式 TCP套接字关闭再使用出现连接服务器错误 SOS!!! 关于如何实现原子操作功能(详见正文)?谢谢! 请高手指点 有关CEdit编辑框的问题?急用! 大哥哥、大姐姐们我怎么实现在Windows网络环境下输入UserID及Password向Domain Server验证该User是否为合法User? DBGrid控件如何绑定一个数据库? 一个格式转换问题 怎样使一个按钮变灰,也就是让它不能用?用CButton的什么属性? 请教 smtp 的问题
我想实现 a+b 的结果为 33.2453
怎么办呢?
Example/* STRTOD.C: This program uses strtod to convert a
* string to a double-precision value; strtol to
* convert a string to long integer values; and strtoul
* to convert a string to unsigned long-integer values.
*/#include <stdlib.h>
#include <stdio.h>void main( void )
{
char *string, *stopstring;
double x;
long l;
int base;
unsigned long ul;
string = "3.1415926This stopped it";
x = strtod( string, &stopstring );
printf( "string = %s\n", string );
printf(" strtod = %f\n", x );
printf(" Stopped scan at: %s\n\n", stopstring );
string = "-10110134932This stopped it";
l = strtol( string, &stopstring, 10 );
printf( "string = %s", string );
printf(" strtol = %ld", l );
printf(" Stopped scan at: %s", stopstring );
string = "10110134932";
printf( "string = %s\n", string );
/* Convert string using base 2, 4, and 8: */
for( base = 2; base <= 8; base *= 2 )
{
/* Convert the string: */
ul = strtoul( string, &stopstring, base );
printf( " strtol = %ld (base %d)\n", ul, base );
printf( " Stopped scan at: %s\n", stopstring );
}
}
Outputstring = 3.1415926This stopped it
strtod = 3.141593
Stopped scan at: This stopped itstring = -10110134932This stopped it strtol = -2147483647 Stopped scan at: This stopped itstring = 10110134932
strtol = 45 (base 2)
Stopped scan at: 34932
strtol = 4423 (base 4)
Stopped scan at: 4932
strtol = 2134108 (base 8)
Stopped scan at: 932