C#,C++,Objective-C中string与int float double的互相转换

先从我能记得的最简单的说起

C# or ASP.NET

string strNum;
int iNum;
float fNum;
double dNum;

//string to int
iNum = int.Parse(strNum);
//string to float
fNum = float.Parse(strNum);
//string to double
dNum = double.Parse(strNum);

//int to string
strNum = iNum.ToString();
//...

接下来是Objective-C 也就是iOS开发

NSString *strNum;
 int iNum;
 //string to int
 iNum = [strNum intValue];
 //...
 //int to string
 [strNum initWithFormat:@"%d", iNum];
 

VC++

 CString strNum;
 int iNum;
 double dNum;
 //string to int
 iNum = atoi(strNum);
 //string to float/double
 dNum = atof(strNum);
 //int to string
 strNum.Format("%d", iNum);
 //if want a style like 001 002 003 ...
 strNum.Format("%03d", iNum);

发表评论

电子邮件地址不会被公开。 必填项已用*标注