I have a numeric string and have observed a discrepency where its intValue
is vastly different from its string value. The code below:
NSString *string = [result objectForKey:@"id"];
NSLog(@"ID %@",string);
NSLog(@"ID as integer %i",[string intValue]);
gives an output:
"ID 100004378121454"
"ID as integer 2147483647"
The only logical guess I can make is that the string is too long to be converted to an int
... In any case I tried longLongValue
and such - to different results but not the one it should be.
Your number(100004378121454) is greater number than a simple int can handle, you have to use long long
type in this case(to not get your number truncated to the int32 maximum value) :
NSString *string = @"100004378121454";
NSLog(@"ID %@",string);
NSLog(@"ID as long long %lli",[string longLongValue]);
Output :
ID 100004378121454
ID as long long 100004378121454
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With