我嘗試將字符串轉換:的NSString NSNumber的轉換
3033547640189791162
用這種方法:
NSNumber * myNumber = [NSNumber numberWithDouble:[tmpId doubleValue]];
這:
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterNoStyle];
NSNumber * myNumber = [f numberFromString:tmpId];
[f release];
和他們倆給我這個號:
<CFNumber 0x13a2b0 [0x3f54c9f8]>{value = +3033547640189791232.00000000000000000000, type = kCFNumberFloat64Type}
insted的的:
<CFNumber 0x1b5550 [0x3f54c9f8]>{value = +3033547640189791232, type = kCFNumberSInt64Type}
編輯
當我嘗試使用:
NSString *tmpId = @""3033547640189791162";
long i = [tmpId longLongValue];
i等於= -1631802438
int i = [tmpId intValue];
i等於= 2147483647
,所以我失去了原有的數值
嘗試'[NSNumber numberWithLongLong:[tmpId longLongValue]];' – Nekto 2012-03-11 10:15:15
爲什麼不使用[NSNumber numberWithInt:]和[NSString intValue:]?據我所知,你期望一個沒有分數的整數值...或者你想控制點後的數字位數? – giorashc 2012-03-11 10:16:58
我編輯我的帖子後,我嘗試了你寫的 – MTA 2012-03-11 10:36:25