Re: PEP 378: Format Specifier for Thousands Separator

Discussion in 'Python' started by Ned Deily, May 21, 2013.

  1. Ned Deily

    Ned Deily Guest

    In article <>,
    Carlos Nepomuceno <> wrote:
    > 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?


    For Python 3.2+ or 2.7, why not just:

    >>> print('Number = {:,}'.format(x))

    Number = 12,345

    --
    Ned Deily,
    Ned Deily, 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. Carlos Nepomuceno
    Replies:
    0
    Views:
    93
    Carlos Nepomuceno
    May 21, 2013
  2. Carlos Nepomuceno
    Replies:
    1
    Views:
    96
    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:
    80
    Chris “Kwpolska†Warrick
    May 21, 2013
  4. Skip Montanaro
    Replies:
    0
    Views:
    94
    Skip Montanaro
    May 21, 2013
  5. Mark Lawrence
    Replies:
    0
    Views:
    82
    Mark Lawrence
    May 21, 2013
Loading...

Share This Page