Function to add commas in numbers?

Mark McEahern marklists at mceahern.com
Thu Jun 20 12:06:10 EDT 2002


> Is there a function that will take, for example, 1234567 and return 
> 1,234,567?

Short answer:  Look into the locale module.

Demo:

  mynum = 123456
  import locale
  locale.setlocale(locale.LC_ALL, "")
  locale.format('%.0f', mynum, 3)
  >>> '123,456'

// m
-






More information about the Python-list mailing list