问题
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