I'm having some values that I need to format into a currency string. It seems that when using NSNumberFormatter to format an amount, the resulting currency string will contain one or more blank spaces.
For instance using the following piece of code to format @"1000"
into the European currency format will result in returning @"1,000,00 €"
. Note the blank space before the currency symbol.
NSNumberFormatter *tempNumberFormatter = [[NSNumberFormatter alloc] init];
[tempNumberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[tempNumberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[tempNumberFormatter setLocale:[NSLocale currentLocale]];
[tempNumberFormatter setGeneratesDecimalNumbers:YES];
[tempNumberFormatter setMaximumFractionDigits:2];
[tempNumberFormatter setMinimumFractionDigits:2];
[tempNumberFormatter setAlwaysShowsDecimalSeparator:YES];
NSString *value = @"1000";
NSNumber *number = [NSNumber numberWithFloat:[value doubleValue]];
NSString *result = [tempNumberFormatter stringFromNumber:number];
[tempNumberFormatter release];
// result = 1.000,00 €
I first thought to solve this easily by just filtering the spaces out of the string but for some reason this does not work, the following piece of code is not doing what I was expecting:
[result replaceOccurrencesOfString:@" " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [result length])];
Is there any way using NSNumberFormatter to return the formatted string without blanc spaces in it ? (1.000,00€
)