Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RLScott

macrumors newbie
Original poster
Jul 17, 2012
3
0
Minnesota
My app displays decimal numbers and I would like it to display in the user's locale so that the decimal point is either a period "." or a comma "," depending on the user's device locale. When I set the device locale to Germany and call localizedStringWithFormat I get the comma "," decimal point as expected. But when I call initWithFormat I always get the period decimal point ".". The docs say that initWithFormat is supposed to follow the user's device locale. I know the device locale is set correctly because localizedStringWithFormat works properly. What am I doing wrong? I have tested this on the iPhone 4.0 Simulator and on a iPhone 3 real device. I am using XCODE 4.2, build 4C199.
 
Post your code.


From the description for localizedStringWithFormat:
This method is equivalent to using initWithFormat:locale: and passing [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] as the locale argument.

From the description for initWithFormat:
Invokes initWithFormat:locale:arguments: with nil as the locale, hence using the canonical locale to format numbers. This is useful, for example, if you want to produce "non-localized" formatting which needs to be written out to files and parsed back later.
 
From the docs:

Discussion
Invokes initWithFormat:locale:arguments: with nil as the locale, hence using the canonical locale to format numbers. This is useful, for example, if you want to produce "non-localized" formatting which needs to be written out to files and parsed back later.

So, if you want to use initWithFormat: and a locale, you'll need to call initWithFormat:locale:
 
From the docs:



So, if you want to use initWithFormat: and a locale, you'll need to call initWithFormat:locale:
Ah, I misread the docs. So initWithFormat is not supposed to follow the user's locale. I guess I'll either switch over to localizedStringWithFormat or initWithFormat:...locale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.