I am using NSNumberFormatter
to format my numbers to strings.
I have a device with Hebrew (israel) region format (settings->General->International->Region Format).
When I try to format the number 100 for instance I get 100 $.
My goal is to remove the space before the currency sign and get just 100$
Asked
Active
Viewed 2,362 times
3

Nikolai Ruhe
- 81,520
- 17
- 180
- 200

user1746700
- 117
- 11
2 Answers
5
I ended up changing positiveSuffix and negativeSuffix properties by removing the spaces from them
because my NSNumberFormatter is static in my application I set them to nil at the end of each use
static NSNumberFormatter *currencyFormatter;
if (!currencyFormatter) {
currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setNegativeFormat:@""];
}
// remove spaces at the suffix
currencyFormatter.positiveSuffix = [currencyFormatter.positiveSuffix stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
currencyFormatter.negativeSuffix = [currencyFormatter.negativeSuffix stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// get the return number
NSString* retNum = [currencyFormatter stringFromNumber:val];
// this code is for the next time using currencyFormatter
currencyFormatter.positiveSuffix = nil;
currencyFormatter.negativeSuffix = nil;
return retNum;

user1746700
- 117
- 11
0
How about just removing all spaces from the string before running it through NSNumberFormatter? (as answered in this question)
NSString *stringWithoutSpaces = [myString
stringByReplacingOccurrencesOfString:@" " withString:@""];
-
2In some formats spaces are used to separate digits instead of commas. I am looking for a safer way – user1746700 Mar 11 '13 at 15:06
-
Perhaps you could replace ` $` with `$`? But I guess there may also be a clause which breaks this. – Patrick Mar 11 '13 at 15:29