Replace Dot With Comma In StringWithFormat:Float?

Discussion in 'iOS Programming' started by Darkroom, Jul 28, 2009.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    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.

    Code:
    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?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  4. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #4
    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:

    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.
     
  5. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    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?
     

    Attached Files:

  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Did you remember to switch your Region Format (Format régional) as well?
     
  7. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #7
    i did not! that was my error. now all is working well. :)

    thanks!
     

Share This Page