long integer value objective-c

半腔热情 提交于 2019-12-22 04:46:26

问题


I have long integer value ( ex: 2705758126 ) in NSString.

When i try to show it: NSLog(@"%i", [myValue integerValue]); it return: 2147483647.

How to show, compare and etc. this long integer


回答1:


Try with

NSLog(@"%lld", [myValue longlongValue]);



回答2:


The documentation recommends using @"%ld" and @"%lu" for NSInteger and NSUInteger, respectively. Since you're using the integerValue method (as opposed to intValue or longLongValue or whatever), that will be returning an NSInteger.




回答3:


You should have a look at Apple's documentation. NSString has the following method:

- (long long)longLongValue

Which should do what you want.




回答4:


from this example here, you can see the the conversions both ways:

NSString *str=@"5678901234567890";

long long verylong;  
NSRange range;  
range.length = 15;  
range.location = 0;  

[[NSScanner scannerWithString:[str substringWithRange:range]] 
       scanLongLong:&verylong];

NSLog(@"long long value %lld",verylong);


来源:https://stackoverflow.com/questions/1147569/long-integer-value-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!