I have an array of strings number with decimal digits, that should be converted in NSNumber:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setDecimalSeparator:@"."];
NSArray * ar = @[@"0.0001",@"0.0010",@"0.002", @"0.02"];
for (NSString * numS in ar) {
NSNumber * num = [formatter numberFromString:numS];
NSLog(@"%@", num);
}
The log prints:
0.0001, 0.001, 2, 0.02
I can't understand why this is happening, I've also tried to change fraction digits properties with no success.
When I write a number with 3 fraction digits where the first two are zero, I always get an integer as result.
I'm using the simulator, Xcode 8.
We had run further tests:
[UPDATE]
I forgot to mention that my device locale is in italian, if I set it in english it works.
Probably set a style and later modify it's decimal separator when the official locale decimal separator doesn't match is not a good idea.
I still do not understand why this only happens for that specific format.
In Italian locale, the .
is the grouping separator. That should basically tell you everything.
The advice is, set the locale, don't tamper with the specific language settings.