I’m trying to support customers whose native language uses commas rather than decimal points, and I created a method that I think should work, but I have not been able to set an NSLocale to produce commas in the value. Here is the method:
-(NSString *)localNumber:(double)d decimals:(int)n{
NSLocale *deLoc = [[NSLocale alloc] initWithLocaleIdentifier:@"fr"];
NSDecimalNumber *dn = [NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%4.*f", n, d]];
NSString *dnS = [dn descriptionWithLocale:deLoc];
return dnS;
}
But the output is always like:
1.67
It appears that descriptionWithLocale has a bug and it isn’t working correctly. I verified that the decimal seperator for the “fr” locale is indeed a comma, but it is using the period.
Anyway, here is a way to do it: