Re: Insert comma in number?

Discussion in 'Python' started by John Posner, Mar 7, 2013.

  1. John Posner

    John Posner Guest

    Peter Otten wrote:

    > Last not least there's the option to employ locale-aware formatting:



    Not quite last ... there's the mind-bending regular expression route:

    import re
    re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "12345678") # 12,345,678
    re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "-54321") # -54,321

    -John
     
    John Posner, Mar 7, 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. cannontrodder
    Replies:
    1
    Views:
    735
    cannontrodder
    Jul 25, 2006
  2. Replies:
    1
    Views:
    456
  3. susie

    insert comma

    susie, Oct 31, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    111
  4. Chris Morris

    format number with comma separators?

    Chris Morris, Aug 5, 2003, in forum: Ruby
    Replies:
    3
    Views:
    370
    Robert Klemme
    Aug 5, 2003
  5. eli m

    Insert comma in number?

    eli m, Mar 6, 2013, in forum: Python
    Replies:
    6
    Views:
    134
    Peter Otten
    Mar 7, 2013
Loading...

Share This Page