Question

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

Was it helpful?

Solution

Try with

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

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top