On Wed, Apr 9, 2008 at 1:04 PM, Kelie <[EMAIL PROTECTED]> wrote: > Is there something in Python built-in function or library that will convert > a number 1205466.654 to $1,205,466.65? To add the "$" sign and set the > decimal place is not a problem, but I don't know how to add the thousands > delimiter.
The locale module provides this functionality. >>> import locale >>> locale.setlocale(locale.LC_ALL, '') 'English_United States.1252' >>> print locale.currency(1205466.654) $1205466.65 >>> locale.currency(1205466.654, grouping=true) $1,205,466.65 That's using the default locale. For me, that's US English. Other languages and countries have different ways of showing currency: >>> locale.setlocale(locale.LC_ALL, "fr") 'French_France.1252' >>> print locale.currency(1205466.654, grouping=True) 1 205 466,65 € -- Jerry -- http://mail.python.org/mailman/listinfo/python-list