objective-c 长整数值objective-c
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1147569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
long integer value objective-c
提问by Shyne
I have long integer value ( ex: 2705758126 ) in NSString.
我在 NSString 中有很长的整数值(例如:2705758126)。
When i try to show it: NSLog(@"%i", [myValue integerValue]); it return: 2147483647.
当我尝试显示它时: NSLog(@"%i", [myValue integerValue]); 它返回:2147483647。
How to show, compare and etc. this long integer
如何显示、比较等这个长整数
回答by IlDan
Try with
试试
NSLog(@"%lld", [myValue longlongValue]);
回答by Dave DeLong
The documentation recommendsusing @"%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.
文档建议对 NSInteger 和 NSUInteger 分别使用 @"%ld" 和 @"%lu"。由于您使用的是 integerValue 方法(而不是 intValue 或 longLongValue 或其他方法),因此将返回一个 NSInteger。
回答by Stig Brautaset
You should have a look at Apple's documentation. NSString has the following method:
你应该看看苹果的文档。NSString 具有以下方法:
- (long long)longLongValue
Which should do what you want.
哪个应该做你想做的。
回答by zoltan
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);

