I have an instance of NSTextField
, e.g. someTextField
, for which I will use the number formatter to limit the input to numbers only.
The problem comes with the localization combined with the specific keyboard layouts used.
I would like to allow both the, say, american and european users to enter their localized decimal separators. As you all know it, in the USA that would be .
and for the good part of Europe that would be ,
(and similar is with the thousands separator, etc. but let's put that to the side for now).
So I wrote the following task:
[numberFormatter setLocale:[NSLocale currentLocale]];
for the instance of the NSNumberFormatter
.
Problems occurs when user who has ,
set as a decimal separator AND US keyboard layout switched on (case fairly often here in Europe) presses the decimal separator key on the numeric keyboard. With the US kyboard layout on, that would give him the .
as the decimal separator but at the same time it'll be ignored in the someTextField
because of the localized settings system-wide. So, if you want to type 1/2
using numeric keyboard only, you'll type 0.5
(US keyboard layout) in the text field and it would be read by the system as 0
because it recognizes only ,
as decimal separator. This is how the program currently is working and I would like to improve it in this regard.
I would like to allow user to type in the .
in the someTextField
and for the system to recognize it as a decimal separator just like it would ,
. This kind of behavior can be seen in Apple's own Calculator application. If you type .
on the numeric keyboard it'll appear as ,
immediately on the screen (for all conditions as described previously).
Question is: is it possible for me to achieve this using an instance of NSNumberFormatter
? If not, is it possible to set on-the-fly conversion of the numerical keyboard decimal separator key output to the decimal separator set system-wide? Or perhaps you have some other suggestions?
Thanks.