2

Im a newbie Xcode user with little coding background. What I am trying to accomplish is to make a simple kg/lb converter app for the iPhone.

Its working great so far, but only problem is that: the users input has to be a value with a dot. User can insert dot using normal (with letters and all that). But when I change to the text field input to decimal keyboard the user can only insert a comma. If the user inserts a number/value with a comma the app crashes (true story).

When launching the app in Xcode simulator the dot is there (which is how I want it) - only when launch on my phone its a comma. The iPhone language and region is set to Norway (although changing any of the these is not a solution).

Screenshot: enter image description here

Is there a way to accomplish what I am trying to do? Thanks!

Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
tcodeb
  • 85
  • 4
  • 11

1 Answers1

6

I think what you see on the keypad is dictated by the General->Language&Region->Advanced, so the reason why you have the comma on the actual device is that this is the correct formatting for the region you have set. This is the correct behaviour, so instead of trying to change that, fix the crash so you can do the math in your app.

I'd suggest using the NSNumberFormatter to get the NSNumber object from string and then do your math.

lawicko
  • 7,246
  • 3
  • 37
  • 49
  • 2
    Agree with this: although English-speaking countries and Central America uses a dot to indicate a decimal point and a comma to separate thousands, mainland Europe and South America uses a dot to separate thousands and a comma to indicate a decimal point. In India you'll see the comma used as a separator but not necessarily of thousands because of lakhs. This concludes the list of regions I'm directly aware of. But, as Iawicko says, `NSNumberFormatter` already knows all that and will deal with it for you. Hooray for already-solved problems! – Tommy Jun 21 '16 at 13:15