一個計算器。每次點擊數字按鈕時,標籤都會附加到「displaystring」可修飾字符串。我注意到,在輸入相同數字的11位數字後,floatValue或intValue函數給了我相同的錯誤。問題與intvalue,floatValue
self.lbldisplay.text正確顯示了顯示字符串的內容。但 的intValue或的floatValue甚至NSCanner公用事業返回,進入10位後,同樣的錯誤
這裏的代碼和日誌:
// original
[self.displayString appendString: [NSString stringWithFormat: @"%i", [sender tag]]];
else { // new entry
//origin test
[self.displayString setString:@""];
[self.displayString appendString: [NSString stringWithFormat: @"%i", [sender tag]]];
bIsTypingANumber = TRUE;
}
// fCurrentNumber = [self.displayString floatValue];
// [self display:fCurrentNumber];
// self.lblDisplay.text = displayString;
NSString *numberString;
NSString *str = [NSString stringWithString:displayString];
NSScanner *theScanner = [NSScanner scannerWithString:str];
[theScanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
[theScanner scanCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:&numberString];
NSLog(@"Attempts: %i", [numberString integerValue]);
self.lblDisplay.text = str;
輸出:
2012-08-26 17:23:34.264 Pilots Fuel[4989:f803] Attempts: 1
2012-08-26 17:23:34.400 Pilots Fuel[4989:f803] Attempts: 11
2012-08-26 17:23:34.552 Pilots Fuel[4989:f803] Attempts: 111
2012-08-26 17:23:34.800 Pilots Fuel[4989:f803] Attempts: 1111
2012-08-26 17:23:34.936 Pilots Fuel[4989:f803] Attempts: 11111
2012-08-26 17:23:35.072 Pilots Fuel[4989:f803] Attempts: 111111
2012-08-26 17:23:35.216 Pilots Fuel[4989:f803] Attempts: 1111111
2012-08-26 17:23:35.344 Pilots Fuel[4989:f803] Attempts: 11111111
2012-08-26 17:23:35.488 Pilots Fuel[4989:f803] Attempts: 111111111
2012-08-26 17:23:35.632 Pilots Fuel[4989:f803] Attempts: 1111111111
2012-08-26 17:23:35.776 Pilots Fuel[4989:f803] Attempts: 2147483647
2012-08-26 17:23:36.056 Pilots Fuel[4989:f803] Attempts: 2147483647
幹得好 - 我得到了相同的「錯誤」,但是很久以後,這個數字非常龐大。 THAAAAAAAANNNKSSS :-))))) –