I have one textfield value like 100,000 using NSNumberFormatter, now I want to edit my textfield, to add one more 0 . After I Want to Change like the text like 1,000,000 but my textfield value is changed as 0
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle: NSNumberFormatterNoStyle];
[numberFormatter setGroupingSize:3];
[numberFormatter setGroupingSeparator:@","];
[numberFormatter setUsesGroupingSeparator:YES];
number= [NSNumber numberWithInt:[textFieldString intValue]];
NSString *numberString = [NSString stringWithFormat:@"$%@",[numberFormatter stringForObjectValue:number]];
try this
回答2:
try like this,
int x=[textfield.text intValue];
you can get the correct value.....
回答3:
Try this code. It may help you
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setFormat:@"#,###"];
NSNumber *averageResponseTime = [NSNumber numberWithInt:[textfield.text intValue]];
//If you print text
[NSString stringWithFormat: @"%@ms",[numberFormatter stringForObjectValue:averageResponseTime]];