I want to get which is the decimal symbol set up on the device. Until now I was using 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 was working fine until now when I am testing on another device (4.3) - null is returned.
What could be the problem?
Is there another way to retrive the decimal symbol?
LATER EDIT:
I can use:
decimalSymbol = [[@"" stringByAppendingFormat:@"%.02f", 1.0f] substringWithRange:range];
but why the other way it doe not work on this particular device?
Swift 4
You can use Locale.current.decimalSeparator or NSLocale.current.decimalSeparator.
The Swift overlay to the Foundation framework provides the Locale structure, which bridges to the NSLocale class.
and
use NSLocale when you need reference semantics or other Foundation-specific behavior.
NSLocale Apple doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With