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. Advertisements

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. =?Utf-8?B?UGF1bA==?=
    Replies:
    1
    Views:
    640
    =?Utf-8?B?UGF1bA==?=
    Feb 1, 2005
  2. Raymond Hettinger
    Replies:
    39
    Views:
    1,759
  3. Douglas
    Replies:
    12
    Views:
    1,186
  4. Carlos Nepomuceno
    Replies:
    1
    Views:
    185
    88888 Dihedral
    May 24, 2013
  5. Andrew Berg
    Replies:
    9
    Views:
    224
    Jerry Hill
    May 24, 2013
  6. Carlos Nepomuceno
    Replies:
    3
    Views:
    178
    88888 Dihedral
    May 22, 2013
  7. Carlos Nepomuceno
    Replies:
    1
    Views:
    157
  8. Dave Angel
    Replies:
    1
    Views:
    158
Loading...