PEP 378: Format Specifier for Thousands Separator

Discussion in 'Python' started by Carlos Nepomuceno, May 21, 2013.

  1. Is there a way to format integers with thousands separator (digit grouping)like the format specifier of str.format()?

    I'm currently using the following:

    >>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))

    Number = 12,345

    'x' is unsigned integer so it's like using a sledgehammer to crack a nut!

    I'd like to have something like:

    sys.stdout.write('Number = %,u\n' % x)


    Is that possible? How can I do it if not already available?
     
    Carlos Nepomuceno, May 21, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ned Deily
    Replies:
    0
    Views:
    90
    Ned Deily
    May 21, 2013
  2. Carlos Nepomuceno
    Replies:
    1
    Views:
    103
    88888 Dihedral
    May 24, 2013
  3. Chris “Kwpolska†Warrick

    Re: PEP 378: Format Specifier for Thousands Separator

    Chris “Kwpolska†Warrick, May 21, 2013, in forum: Python
    Replies:
    0
    Views:
    94
    Chris “Kwpolska†Warrick
    May 21, 2013
  4. Skip Montanaro
    Replies:
    0
    Views:
    105
    Skip Montanaro
    May 21, 2013
  5. Mark Lawrence
    Replies:
    0
    Views:
    88
    Mark Lawrence
    May 21, 2013
Loading...

Share This Page