View Full Version : Replace Dot With Comma In StringWithFormat:Float?
Darkroom
Jul 29, 2009, 02:17 AM
ok... so i have a string that displays a floating point number with 2 decimal places. by default, float displays with a period. however, my app is localized into french (english dev base), and in québec and france, numbers are displayed with a comma, not a period.
self.myNumberString = [NSString stringWithFormat:@"%.2f", aFloat];
how do i display this string float with a comma IF it is currently being viewed in french localization?
PhoneyDeveloper
Jul 29, 2009, 04:44 AM
Look at NSNumberFormatter.
dejo
Jul 29, 2009, 09:46 AM
Use localizedStringWithFormat: instead?
Darkroom
Jul 30, 2009, 08:44 AM
humm... localizedStringWithFormat doesn't seem to be working for me, although after reading about it on the docs, it's exactly what i'm looking for. here's my code:
self.lightSizeString = [NSString localizedStringWithFormat:@"%.2f x %.2f %@", ((dragFrame.origin.x + kDragViewWidthHeight - centerPoint.x) * 2) / 163, ((dragFrame.origin.y + kDragViewWidthHeight - centerPoint.y) * 2) / 163, self.lightSizeUnit];
the resulting string in french environment still displays the dot instead of the comma.
Darkroom
Jul 30, 2009, 12:34 PM
i've attached a tiny sample project. switching the simulator (or device) into French results in the string's float still being displayed with a dot.
any ideas?
dejo
Jul 30, 2009, 01:00 PM
switching the simulator (or device) into French...
Did you remember to switch your Region Format (Format régional) as well?
Darkroom
Jul 30, 2009, 03:03 PM
Did you remember to switch your Region Format (Format régional) as well?
i did not! that was my error. now all is working well. :)
thanks!
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.