3
I need to create a Uitextfield to add money values. But I need the user to see the value being added to Uitextfield in the order the user type. Example: User type 1 - Uitextfield appears 0.01 User type 5 - Uitextfield appears 0.15 User type 0 - Uitextfield appears 1.50
There enters my problem, when the user type the 4th digit, in my case this appearing 1,5,00 and not 15,00 as wish.
Follow the formatting code:
NSNumberFormatter *valueTextFieldFormatter= [NSNumberFormatter new];
[valueTextFieldFormatter setPositiveFormat:@"#0,0"];
[valueTextFieldFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *num = [textField.text stringByReplacingOccurrencesOfString:@"," withString:@""];
textField.text = [valueTextFieldFormatter stringFromNumber:[NSNumber numberWithInt:[num floatValue]]];
The code I reported is within the method
shouldChangeCharactersInRange
– David Batista