I want the users to be able to input values above 0 for a money amount in my application. So 0,0 or any representation of zero will be unacceptable but 0,1 will be accepted, for example.
In order to do this, I was planning to get the float value of NSString and compare it to 0.0 but this does not work since our decimal numbers need to be seperated with comma, always (due to a business requirement). If the commas were dots, then the comparison does the job.
What's the most decent way to replace commas with dots in my amount texts?
PS: The user is limited to enter only numbers and just one comma, for the decimal part. And actually I was wondering if this is sthg that could be done with number formatters or so...
Thx in advance
Here's a neat way to use NSScanner
:
NSScanner *scanner = [NSScanner localizedScannerWithString:theInputString];
float result;
[scanner scanFloat:&result];
You could just use stringByReplacingOccurrencesOfString
NSString *newString = [ammount stringByReplacingOccurrencesOfString:@"," withString:@"."];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With