Re: Thousand Seperator

2008-03-14 Thread Paul MĀ¢Nett
Eddie Corns wrote: > [EMAIL PROTECTED] writes: > >> I'm trying to find some code that will turn: > >> 100 -> 100 >> 1000 -> 1,000 >> 100 -> 1,000,000 >> -1000 -> -1,000 > >> I know that can be done using a regular expression. In Perl I would do >> something like: > >> sub thousand { >>

Re: Thousand Seperator

2008-03-14 Thread Jeroen Ruigrok van der Werven
-On [20080314 18:11], [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote: >But I cannot find how to do this in Python. I am not sure of your goal, but if you need this for localization purposes, look at Babel (http://babel.edgewall.org/). In particular http://babel.edgewall.org/wiki/ApiDocs/babel.numbers

Re: Thousand Seperator

2008-03-14 Thread Shane Geiger
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/python/lib/decimal-recipes.html Eddie Corns wrote: > [EMAIL PROTECTED] writes: > > >> I'm trying to find some code that will turn: >> > > >> 100 -> 100 >> 1000 -> 1,000 >> 100 -> 1,000,000 >> -1000 -> -1,000 >> > > >

Re: Thousand Seperator

2008-03-14 Thread Eddie Corns
[EMAIL PROTECTED] writes: >I'm trying to find some code that will turn: >100 -> 100 >1000 -> 1,000 >100 -> 1,000,000 >-1000 -> -1,000 >I know that can be done using a regular expression. In Perl I would do >something like: >sub thousand { >$number = reverse $_[0]; >$number =

Re: Thousand Seperator

2008-03-14 Thread Paul Rubin
[EMAIL PROTECTED] writes: > 100 -> 100 > 1000 -> 1,000 > 100 -> 1,000,000 > -1000 -> -1,000 def sep(n): if n<0: return '-' + sep(-n) if n<1000: return str(n) return '%s,%03d' % (sep(n//1000), n%1000) -- http://mail.python.org/mailman/listinfo/python-list

Thousand Seperator

2008-03-14 Thread ewanfisher
I'm trying to find some code that will turn: 100 -> 100 1000 -> 1,000 100 -> 1,000,000 -1000 -> -1,000 I know that can be done using a regular expression. In Perl I would do something like: sub thousand { $number = reverse $_[0]; $number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;