Search code examples
iphoneobjective-clocale

On the iPhone, what would be the locale identifier for forcing US english representations of numbers?


In particular I want to guarantee that the formatting of a number uses , (commmas) for separating digits regardless of the current locale of the device.

NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init];
[numFormatter setLocal:@"??????"]

Solution

  • The U.S. uses a period as a decimal separator. I assume you mean that you want to use a comma as a grouping separator.

    You don't need to set the locale for this in your NSNumberFormatter, you can set both directly using code like the following:

    [numFormatter setGroupingSeparator:","];
    [numFormatter setUsesGroupingSeparator:YES];
    [numFormatter setDecimalSeparator:"."];