I want to add a ',' in '11000' like this '11,000' and decimal ('.') in 465 like 4.65. I wrote this for Comma :
- (BOOL) textField: (UITextField *)textField shouldChangeCharactersInRange: (NSRange)range replacementString: (NSString *)string {
NSString *unformattedValue;
NSNumberFormatter *formatter;
NSNumber *amount;
switch ([textField tag]) {
case 102:
unformattedValue = [textField.text stringByReplacingOccurrencesOfString:@"," withString:@""];
unformattedValue = [unformattedValue stringByReplacingOccurrencesOfString:@"." withString:@""];
formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setGroupingSeparator:@","];
[formatter setDecimalSeparator:@"."];
amount = [NSNumber numberWithInteger:[unformattedValue intValue]];
textField.text = [formatter stringFromNumber:amount];
break;
default:
break;
}
return YES;
}
And what this doing is it actually putting the comma like this 1,1000 for 11000. And i am not able to do anything close for decimal. Please help!!