I have a problem with NSTextField in Cocoa. Is there a way to remove regional settings from a NSTextField
I want the user to only enter values like so 0.6, 0.7 but if the user is not from US he is forced to enter like this 0,6, 0,7
So if the user is not US user if he enters 0.7 [textField floatValue] will return 0
and if the user is US and he enters 0,7 [textField floatValue] will return 0
Well lets say that is something i can accept but then i want to format the value and display it only with 3 decimals
this will work for US but will not work for non US even though value is a correct float (eg 0.3)
[textField setStringValue:[NSString stringWithFormat:@”%.3f”,value]];
textfield is of type NSTextField
Thank you!
You should be using
NSNumberFormatterinstead of+[NSString stringWithFormat:]. In fact, usingNSNumberFormatterallows you to:amongst other features.
If your
NSTextFieldis in a nib file, Interface Builder/Xcode 4 allows you to link theformatteroutlet to anNSNumberFormatterinstance. You can also do it programatically by sending-setFormatter:to the text field.