Permalink
Browse files

Fix it not working for regions with a decimal separator that is not a…

… period
  • Loading branch information...
mpatric committed Nov 28, 2013
1 parent ed20759 commit fbc0ac704b95f7781354bc1e64b87714d6b0595b
Showing with 2 additions and 2 deletions.
  1. +2 −2 DecimalInput/MyViewController.m
@@ -46,7 +46,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

- (void)viewWillAppear:(BOOL)animated {
// Default value
self.textField.text = @"0.00";
self.textField.text = [NSString stringWithFormat:@"0%@00", self.decimalSeparator];
// Pop up keyboard
[self.textField becomeFirstResponder];
}
@@ -68,7 +68,7 @@ - (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange
int currentValue = [currentString intValue];
NSString* format = [NSString stringWithFormat:@"%%.%df", self.maximumFractionDigits];
double minorUnitsPerMajor = pow(10, self.maximumFractionDigits);
NSString* newString = [NSString stringWithFormat:format, currentValue / minorUnitsPerMajor];
NSString* newString = [[NSString stringWithFormat:format, currentValue / minorUnitsPerMajor] stringByReplacingOccurrencesOfString:@"." withString:self.decimalSeparator];
if (newString.length <= MAX_LENGTH) {
textField.text = newString;
// if the cursor was not at the end of the string being entered, restore cursor position

0 comments on commit fbc0ac7

Please sign in to comment.