PROC中的型別轉換

2021-06-16 04:16:31 字數 2094 閱讀 5947

一、在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

matlab中強制型別轉換 型別轉換

上一期提到 隱式型別強制轉換 implicit type coercion 隱式型別強制轉換會造成意外。為了避免出現意外,c 提供了明式型別轉換,允許程式設計師通過使用型別轉換操作 cast operator 主動轉換資料的型別。型別轉換操作也可直接稱為型別轉換 type conversion ty...

oracle中pro c的學習

一 pro c 程式概述 1 什麼是pro c程式 在oracle 資料庫治理和系統中,有三種訪問資料庫的方法 1 用sql plus,它有sql命令以互動的應用程式訪問資料庫 2 用 語言應用開發工具開發的應用程式訪問資料庫,這些工具有sql froms,ql reportwriter,sql m...

Pro C中CLOB的使用

include include include 包含oci標頭檔案 include 包含sqlca標頭檔案 include void connect void sql error void init clob void read clob void write clob int main retur...