NSNumberFormatter how to remove spaces in currency symbol

I have some values ​​that I need to format into a currency string. It appears that when using NSNumberFormatter to format the sum, the resulting currency string will contain one or more spaces.

For example, using the following code snippet to format @"1000"in the European currency format will result in a refund @"1,000,00 €". Note the 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 € 

At first, I decided to easily solve this problem by simply filtering out the spaces from the string, but for some reason this will not work, the following code fragment does not fulfill what I expected:

[result replaceOccurrencesOfString:@" " withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [result length])];

Is it possible to use NSNumberFormatter to return a formatted string without blanc spaces? ( 1.000,00€)

+3
2

, . , NSNumberFormatter, , .

- . , NSLog,

formattedPrice = [formattedPrice stringByReplacingOccurrencesOfString:@" " withString:@""];

( , , ...)

+5

, ? "€ 1,000.00", ().

0

Source: https://habr.com/ru/post/1740989/


All Articles