I want to get which is the decimal character installed on the device. So far I have used this method:
NSString *decimalSymbol; NSNumberFormatter *f = [[NSNumberFormatter alloc] init]; [f setNumberStyle:NSNumberFormatterDecimalStyle]; [f setMinimumFractionDigits:2]; [f setMaximumFractionDigits:2]; [f setGroupingSeparator:@" "]; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; [formatter setMinimumFractionDigits:2]; [formatter setMaximumFractionDigits:2]; [formatter setGroupingSeparator:@" "]; NSRange range = {1,1}; decimalSymbol = [[formatter stringFromNumber:[f numberFromString:[@"" stringByAppendingFormat:@"%.02f", 1.0f]]] substringWithRange:range]; [formatter release]; [f release];
It worked fine so far, when I test another device (4.3) - returns null . What could be the problem?
Is there any other way to get the decimal character?
MORE CHANGE:
I can use:
decimalSymbol = [[@"" stringByAppendingFormat:@"%.02f", 1.0f] substringWithRange:range];
but why the other way it does not work on this particular device?
objective-c iphone cocoa-touch nsnumberformatter
Cristic
source share