I’ve been building a currency removal function which will work across the globe.
However a bug has come to light and unsure why.
+(double)removeFormatPrice:(NSString *)strPrice {
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init]
autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber* number = [currencyFormatter numberFromString:strPrice];
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init]
autorelease];
NSMutableString *mstring = [NSMutableString stringWithString:strPrice];
NSRange wholeShebang = NSMakeRange(0, [mstring length]);
[mstring replaceOccurrencesOfString: [formatter decimalSeparator]
withString: @"."
options: 0
range: wholeShebang];
double newPrice = [mstring doubleValue];
if (number == nil) {
return newPrice;
} else {
return [number doubleValue];
}
}
If I pass in 1,000.00 then it replaces the dot (period / full stop) it should just do that, but it also replaces the comma. Newprice comes out as 1. Heres my full debug…

Use this