2015-02-01 4 views
0

사용자가 텍스트 필드에 숫자 900000을 입력하게하고 10 진수로 포맷 한 다음 화면에 900,000으로 표시합니다. 형식이 지정된 텍스트 필드에서 숫자 값을 추출하려고하면 반환되는 숫자는 900입니다. 제안?UItextfield post-NSFormatter 10 진수 변환에서 숫자 값 추출

+0

당신이 문자열 형식 지정자를 시도? https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html –

답변

0

쉼표 제거를 시도해 보셨습니까?

str = [str stringByReplacingOccurrencesOfString:@"," 
            withString:@""]; 

int value = [str intValue]; 
1

당신은 전에 숫자로 변환에

stringByReplacingOccurrencesOfString:@"," withString:@""

과 함께 삭제 할 수 그러나 이것은 '소수점으로 사용되는 세계의 많은에서 작동하지 않습니다.

더 나은는 NSNumberFormatter를 사용 :

NSNumberFormatter *numberFormatter = [NSNumberFormatter new]; 
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle; 
NSNumber *numberObject = [numberFormatter numberFromString:@"900,000"]; 
NSLog(@"numberObject: %@", numberObject); 
int numberInt = [numberObject intValue]; 
NSLog(@"numberInt: %d", numberInt); 

출력 :

numberObject : 900000
numberInt : 900000