2011-11-09 3 views
0

Im new to iphone, 텍스트 필드가 하나 있습니다. 사용자 정의 숫자 버튼을 클릭하면 값이 텍스트 필드에 인쇄됩니다. 예를 들어 텍스트 필드에 값을 입력하면 (예 : 1234), 0.00과 같은 float 값을 원하게됩니다. 방법?

Text1.Text 사용 = [이 NSString ALLOC] initWithFormat @ "@ %의 % d에"Text1.Text 사용, num.tag];

1234

+0

중복 가능성 [아이폰 텍스트 필드에 플로트 값을 표시 할 수 있는가? (http://stackoverflow.com/questions/8052671/how-to-display-float-values-in-textfield-in- 아이폰) –

답변

0

Text1.Text 사용 = [있는 NSString stringWithFormat을 : @ "$ % 0.2f 달러", 1234] 시도 할 수 있습니다;

여기서 1234를 원하는 변수로 바꿀 수 있습니다.

0

NSNumberFormater가 표시됩니다.

NSNumberFormatter *numberFormatter=[[NSNumberFormatter alloc] init]; 
    [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; 
    [numberFormatter setMinimumFractionDigits:2]; 
[text1 setText:[numberFormatter stringFromNumber:[NSNumber numberWithFloat:[text1.text floatValue]]]; 
관련 문제