开发者

Problems converting NSString to unsigned long long [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

Storing and retrieving unsigned long long value to/from NSString

Having problems trying to convert an NSString to an unsigned long long. Heres the code:

    NSString* mp3开发者_如何学编程id = [[NSString alloc] initWithUTF8String:"16902439379132728577"];

    NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
    NSNumber* persistentId = [f numberFromString:mp3id];  

    unsigned long long test = [persistentId unsignedLongLongValue];
    NSLog(@"unsigned long long is %llu",test);
    [f release];

Output:

2011-07-09 15:28:06.834 NBUnityMP3Plugin[443:307] unsigned long long is 16902439379132729344 2011-07-09 15:28:06.847 NBUnityMP3Plugin[443:307] persistant id is 1.690243937913273e+19

To make it clearner:

16902439379132728577 - input
16902439379132729344 - output

Ideally I would like to get that unsigned long long into an NSNumber variable. I figured that would be easy if I only had an unsigned long long.


NSNumberFormatter is representing the unsigned long long as a float, and I thought setting [f setAllowsFloats:NO]; after initializing the NSNumberFormatter would fix the problem. It doesn't seem to do that, though (returning nil when trying to set the number). It is possible that 16902439379132728577 is too long for NSNumberFormatter to handle as an integer, and it may only handle signed integers in the long long range.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜