字串,數字之間的轉換

2021-04-19 08:21:22 字數 2227 閱讀 9436

數字---->字串

cstring ntos(double d)

else

if(sign==1) str.insert(0,"-");

return str;

}字串---->數字

double ston(cstring str)

10進製-----〉2進製

void ccalculation::dec2bin(cstring *strexp)

int pos=strexp->find('.');

cstring str,strdec;

_int64 ndecint;

double ddec;

if(pos!=-1) 

ndecint=atoi(strdec.getbuffer(0));

strdec=strexp->right(strexp->getlength()-pos); 

}else

ndecint=atoi(strexp->getbuffer(0));

}strexp->empty();

while(ndecint!=0)

*strexp+=".";

if(pos!=-1)

}if(bminus) strexp->insert(0,"-");

}10進製---------〉16進製制

void ccalculation::dec2hex(cstring *strexp/*strexp須為數字*/)

int pos=strexp->find('.');

cstring str,strdec;

int ndecint;

double ddec;

if(pos!=-1) 

else

strexp->empty();

while(ndecint!=0)

*strexp+=".";

if(pos!=-1)

}if(bminus) strexp->insert(0,"-");

if(strexp->find("-1")!=-1 && bminus!=1) *strexp="太大無法表示";

}void ccalculation::bin2dec(cstring *strexp)

if(ch=='0' || ch=='1' ||ch==46)

else

break;

}if(i==pos-1) 

index=i;

pos=strtmp.find(".");

if(pos!=-1)

strtmp.makereverse();

len=strtmp.getlength();

for(i=0;i

len=strdf.getlength();

for(i=0;i

strtmp=ntos(dx);

strexp->insert(index+1,strtmp);

pos=strexp->find("xb");}}

void ccalculation::dec2hex(cstring *strexp/*strexp須為數字*/)

int pos=strexp->find('.');

cstring str,strdec;

int ndecint;

double ddec;

if(pos!=-1) 

else

strexp->empty();

while(ndecint!=0)

*strexp+=".";

if(pos!=-1)

}if(bminus) strexp->insert(0,"-");

if(strexp->find("-1")!=-1 && bminus!=1) *strexp="太大無法表示";

}void ccalculation::dec2oct(cstring *strexp)

int pos=strexp->find('.');

cstring str,strdec;

int ndecint;

double ddec;

if(pos!=-1) 

else

strexp->empty();

while(ndecint!=0)

*strexp+=".";

if(pos!=-1)

}if(bminus) strexp->insert(0,"-");

}

Python 字串數字之間轉換

int x base 將x轉換為乙個整數 long x base 將x轉換為乙個長整數 float x 將x轉換到乙個浮點數 complex real imag 建立乙個複數 str x 將物件 x 轉換為字串 repr x 將物件 x 轉換為表示式字串 eval str 用來計算在字串中的有效py...

數字與字串之間的轉換

c語言為我們提供了數字和字串之間的轉換函式,這些函式有很多,常用的有 整型數轉字串函式itoa char itoa int value,char string,int radix int value 被轉換的整數,char string 轉換後儲存的字元陣列,int radix 轉換進製數,如2,8...

字串和數字之間的轉換

1 字串數字之間的轉換 1 string char string str ok char p str.c str 2 char string char p ok string str p 3 char cstring char p ok cstring m str p 或者 cstring m st...