Hi, all
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
Hi, all
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
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.
You should have a look at Apple's documentation. NSString has the following method:
- (long long)longLongValue
Which should do what you want.
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);