Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDecimalNumber decimalNumberWithString: ignores current locale

Tags:

According to the documentation, [NSDecimalNumber decimalNumberWithString:] should use the locale decimal separator:

Whether the NSDecimalSeparator is a period (as is used, for example, in the United States) or a comma (as is used, for example, in France) depends on the default locale.

But when I try it, this code:

NSLog(@"%@", [NSDecimalNumber decimalNumberWithString:@"100,1"]);
NSLog(@"%@", [NSDecimalNumber decimalNumberWithString:@"100,1" locale:NSLocale.currentLocale]);

Gives...

100
100.1

...as output on both iOS 5 and iOS 6. I've tried with Swedish and French as regional settings as both these countries use comma (,) as decimal separator.

Shouldn't the output be the same?

(I know I can use [NSDecimalNumber decimalNumberWithString:locale:] to force the behavior, so this question is not about finding an alternative, just if this is a bug or I'm doing something wrong)