Search code examples
ios5nsnumberformatter

NSNumberFormatter numberFromString doesn't return number from currency string


numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle;    
NSLog(_priceTF.text);
NSNumber *price = [numberFormatter numberFromString:_priceTF.text];
NSLog([price stringValue]);

Console output: 25 kr

P.S. : price is nil.


Solution

  • Currently, I get NSNumber so (but that's weird):

    NSString *priceNoCurrency = [_priceTF.text stringByReplacingOccurrencesOfString:numberFormatter.currencySymbol withString:@""];
    NSNumber *price = @(priceNoCurrency.integerValue);