Paul Rubin wrote:
> "To iterate is human; to recurse, divine":
>
> def commafy(n):
>if n < 0: return '-' + commafy(-n)
>if n >= 1000: return '%s,%03d' % (commafy(n//1000), n % 1000)
>return '%s'% n
>
> I don't like the locale solution because of how messy locales are.
"abcd" <[EMAIL PROTECTED]> writes:
> 1890284
>
> would be:
>
> 1,890,284
"To iterate is human; to recurse, divine":
def commafy(n):
if n < 0: return '-' + commafy(-n)
if n >= 1000: return '%s,%03d' % (commafy(n//1000), n % 1000)
return '%s'% n
I don't like the locale s
Yu-Xi Lim wrote:
> >>> b = 189028499
> >>> ','.join([str(b)[::-1][x:x+3] for x in range(len(str(b)))[::3]])[::-1]
>
> '-,189,028,499'
Oops, mis-paste
>>> b = -189028499
>>> ','.join([str(b)[::-1][x:x+3] for x in range(len(str(b)))[::3]])[::-1]
--
http://mail.python.org/mailman/listinfo/pyt
Tim Williams wrote:
a = 1890284
','.join([str(a)[::-1][x:x+3] for x in range(len(str(a)))[::3]])[::-1]
> '1,890,284'
>
> Ugly !
>
>>> b = 189028499
>>> ','.join([str(b)[::-1][x:x+3] for x in range(len(str(b)))[::3]])[::-1]
'-,189,028,499'
>>> c = 1890284.1
>>> ','.join([str(c)[::
On 7 Aug 2006 07:55:11 -0700, abcd <[EMAIL PROTECTED]> wrote:
> if i have a number, say the size of a file, is there an easy way to
> output it so that it includes commas?
>
> for example:
>
> 1890284
>
> would be:
>
> 1,890,284
>
I was bored !!
>>> a = 1890284
>>> ','.join([str(a)[::-1][x:x+3] f
abcd wrote:
> if i have a number, say the size of a file, is there an easy way to
> output it so that it includes commas?
>
> for example:
>
> 1890284
>
> would be:
>
> 1,890,284
see also this thread:
http://tinyurl.com/qf6ew
rd
--
http://mail.python.org/mailman/listinfo/python-list
In <[EMAIL PROTECTED]>, abcd wrote:
> if i have a number, say the size of a file, is there an easy way to
> output it so that it includes commas?
>
> for example:
>
> 1890284
>
> would be:
>
> 1,890,284
I think this comes close:
In [23]: import locale
In [24]: locale.setlocale(locale.LC_ALL