NSNumberFormatter
does provide ways to deal with commas, dots and spaces, in fact, it does this very well. There's the "leniency" that tries to guess the best formatting:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setLenient:YES];
NSLog(@"%@", [formatter numberFromString:@"123,456.78"]);
NSLog(@"%@", [formatter numberFromString:@"123 456 78"]);
Output:
123456.78
12345678
It works, but if the user starts mixing things (e.g 123,456 789.105
) it fails. I would personally replace all occurrences of spaces, and then use the number formatter.
If you're worried about efficiency, I need to inform you: don't. It's just a text input that will be used once for every run. If you were doing this every time the user scrolls something, or thousands of calculations, then you should worry.
Also, if the user is going to input very large numbers, don't you think there are better interfaces for handling that? I'm not sure if you're writing an iOS or OSX app, so it depends. Maybe give him a scientific notation set of buttons, where he can pick the number and the power?