PROC中的类型转换

一、在C语言中:
(1)字符型到整型可用ATOI() ATOL(),SSCANF()
(2)整型,浮点型到字符型,可用SPRINTF()
(3)字符型到浮点型用ATOF()不行,最好用SSCANF(),举例如下:

EXEC SQL BEGIN DECLARE SECTION;
double d_demo;
float f_demo;
char ac_text[20]="222";
EXEC SQL END DECLARE SECTION;

(1)sscanf(ac_text, "%f", &d_demo);
printf("ac_text=%s,d_demo=%f ",ac_text,d_demo);

(2)sscanf(ac_text, "%lf", &d_demo);
printf("ac_text=%s,d_demo=%f ",ac_text,d_demo);

(3)sscanf(ac_text, "%f", &d_demo);
printf("ac_text=%s,d_demo=%lf ",ac_text,d_demo);

(4)sscanf(ac_text, "%lf", &d_demo);
printf("ac_text=%s,d_demo=%lf ",ac_text,d_demo);

printf("******************* ");
(5)sscanf(ac_text, "%f", &f_demo);
printf("ac_text=%s,f_demo=%f ",ac_text,f_demo);

(6)sscanf(ac_text, "%lf", &f_demo);
printf("ac_text=%s,f_demo=%f ",ac_text,f_demo);

(7)sscanf(ac_text, "%f", &f_demo);
printf("ac_text=%s,f_demo=%lf ",ac_text,f_demo);

(8)sscanf(ac_text, "%lf", &f_demo);
printf("ac_text=%s,f_demo=%lf ",ac_text,f_demo);

输出的结果:
ac_text=222.00,d_demo=0.000000
ac_text=222.00,d_demo=222.000000
ac_text=222.00,d_demo=222.000032
ac_text=222.00,d_demo=222.000000
*******************
ac_text=222.00,f_demo=222.000000
ac_text=222.00,f_demo=0.000000
ac_text=222.00,f_demo=222.000000
ac_text=222.00,f_demo=0.000000
d_demo=atof(ac_text);
printf("ac_text=%s,atof(ac_text)=%f ",ac_text,d_demo);

d_demo=atof(ac_text);
printf("ac_text=%s,atof(ac_text)=%lf ",ac_text,d_demo);

f_demo=atof(ac_text);
printf("ac_text=%s,atof(ac_text)=%f ",ac_text,f_demo);

f_demo=atof(ac_text);
printf("ac_text=%s,atof(ac_text)=%lf ",ac_text,f_demo);

输出的结果:
ac_text=222.00,atof(ac_text)=1243288.000000
ac_text=222.00,atof(ac_text)=1243288.000000
ac_text=222.00,atof(ac_text)=1243288.000000
ac_text=222.00,atof(ac_text)=1243288.000000

从上面的结果可见:
DOUBLE型应采用sscanf(ac_app_capcity, "%lf", &d_app); 打印用"%lf","%f" 都可以. (2),(4)正确
FLOAT型应采用sscanf(ac_app_capcity, "%f", &d_app); 打印用"%lf","%f" 都可以. (5),(7)正确
采用ATOF()转换的结果都是错的,所以不要用它。
二、写表或从表中取数据时:
(1)字符型与整型之间可不用转换,采用默认方式。
(2)字符型与浮点型之间可不用转换,采用默认方式。
(3)日期型与字符型之间可用TO_CHAR(),TO_DATE()。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值