Kris Bixler
Kris Bixler

Reputation: 196

UIKeyboardTypeDecimalPad localization

I noticed that UIKeyboardTypeDecimalPad was added in iOS 4.1, and started using it. During the course of my testing, I switched both the language and region to French in the International section of Settings. I expected the decimal key on the keypad in my app to change from a "." to a "," but it didn't.

All I'm doing is this:

_textFieldUnitCost.keyboardType = UIKeyboardTypeDecimalPad;

Any ideas?

Upvotes: 2

Views: 918

Answers (2)

Farini
Farini

Reputation: 933

One way around it is to just accept the punctuation because it is a decimalpad and than change it when you pass it as a string to display.

NSString *firstString = @"102.08", *finalString;

finalString = [[firstString stringByReplacingOccurancesOfString:@"." withString:@","];
//string value returns 102,08

That will work if you just need to display. It will not work if your doing math with that string. You actually can't. Now you can store it as a float and then when you convert to a string you do those 2 lines of code

Upvotes: 0

Kris Bixler
Kris Bixler

Reputation: 196

As of 4.2.1 the decimal key on the keypad now changes from a "." to "," when switching to a language/region that uses a ","

Upvotes: 2

Related Questions