欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

笔记:long、longlong、int、float、NSString相互转换

程序员文章站 2022-08-31 12:26:08
NSString *string = @"123"; // 1.字符串转int int intString = [string intValue]; // 2.int转字符串 NSString *stringInt = [NSString stringWithFormat:@"%d",intStri... ......
nsstring *string = @"123";

// 1.字符串转int
int intstring = [string intvalue];

// 2.int转字符串
nsstring *stringint = [nsstring stringwithformat:@"%d",intstring];

// 3.字符串转float
float floatstring = [string floatvalue];

// 4.float转字符串
nsstring *stringfloat = [nsstring stringwithformat:@"%f",floatstring];


  long longvalue = 104024;    
// 5.long 型转换字符串
 nsnumber *longnumber = [nsnumber numberwithlong:longvalue];
nsstring *longstr = [longnumber stringvalue];
        
 // 6.long long 型转换字符串
nsnumber *longlongnumber = [nsnumber numberwithlonglong:longvalue];
nsstring *longlongstr = [longlongnumber stringvalue];

//7.字符串转long
[str longlongvalue];