Thousand Seperator
Shane Geiger
sgeiger at ncee.net
Fri Mar 14 13:50:40 EDT 2008
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/python/lib/decimal-recipes.html
Eddie Corns wrote:
> ewanfisher at gmail.com writes:
>
>
>> I'm trying to find some code that will turn:
>>
>
>
>> 100 -> 100
>> 1000 -> 1,000
>> 1000000 -> 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;
>> return scalar reverse $number;
>> }
>>
>
>
>> But I cannot find how to do this in Python.
>>
>
> Look at the locale module. If you're producing the numbers yourself then they
> get printed in that format otherwise you can convert them to numbers first.
>
> Eddie
>
>
--
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net | 402-438-8958 | http://www.ncee.net
Leading the Campaign for Economic and Financial Literacy
More information about the Python-list
mailing list