开发者

Formatting the number entered in textfield in iPhone

开发者 https://www.devze.com 2023-01-03 04:10 出处:网络
I have a text field where the user enters a number, which is in th开发者_StackOverflowe range of thousands.

I have a text field where the user enters a number, which is in th开发者_StackOverflowe range of thousands.

I want the text field to be formatted as the user enters the number, example : 200000 should become 200,000.

how do i go about doing this??

Many Thanks,

S


I had the same question!

Here's how you do it. You want to use NSNumberFormatter and set it to use Decimal style:

NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
[formatter setNumberStyle: NSNumberFormatterDecimalStyle];  
textField.text = [formatter stringFromNumber: [formatter numberFromString:textField.text]];

Replace textField with the name of your UITextField variable.

0

精彩评论

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