Re: numeric formatting

2006-03-27 Thread jtm
Quick and nasty: from django.core import template register = template.Library() @register.filter(name='commas') def commas(value): return "".join(commafy(value)) def commafy(s): pieces = s.split(".") l = len(pieces[0]) for i in range(0,l): if (l -

Re: numeric formatting

2006-03-27 Thread Nebojša Đorđević
Rock wrote: > Is there a template filter for turning a large integer into a human > readable number? > > 1234567 --> 1,234,567 > 12345 --> 12,345 > > I don't think that python built-in formatting can do this. (Am I > wrong?) > > Assuming there isn't already a simple filter that will do this,

Re: numeric formatting

2006-03-24 Thread Eric Walstad
On Friday 24 March 2006 12:23, Jacob Kaplan-Moss wrote: > > I don't think that python built-in formatting can do this. (Am I > > wrong?) > > Actually, locale.format will do it for you, IIRC. >>> import locale >>> locale.setlocale(locale.LC_ALL, '') 'en_US.UTF-8' >>> locale.format("%d", 1234567, T

Re: numeric formatting

2006-03-24 Thread Jacob Kaplan-Moss
On Mar 24, 2006, at 1:48 PM, Rock wrote: > Is there a template filter for turning a large integer into a human > readable number? > > 1234567 --> 1,234,567 > 12345 --> 12,345 > > I don't think that python built-in formatting can do this. (Am I > wrong?) Actually, locale.format will do it for yo

numeric formatting

2006-03-24 Thread Rock
Is there a template filter for turning a large integer into a human readable number? 1234567 --> 1,234,567 12345 --> 12,345 I don't think that python built-in formatting can do this. (Am I wrong?) Assuming there isn't already a simple filter that will do this, what do I need to learn about in