0

I have set the following in my settings.py file:

USE_L10N = True
NUMBER_GROUPING = 3
THOUSAND_SEPARATOR = '#'
USE_THOUSANDS_SEPARATOR =True

Yet my numbers are still printing out 12000.00. Can anyone point me in the right direction?

(I'm on Django 1.3)

Robert Johnstone
  • 5,431
  • 12
  • 58
  • 88

2 Answers2

1

There's a helper template library that ships with Django (humanize) which has a filter called intcomma that sounds like it would do what you want.

Usage in a template:

{% load humanize %}
${{ value|intcomma }}
Dan Breen
  • 12,626
  • 4
  • 38
  • 49
  • Thanks. I should have mentioned that I am cycling through the variables dynamically, hence why I'm wondering why when I have set everything I still don't get my int's seperated out – Robert Johnstone Oct 31 '11 at 15:07
0

I couldn't find any locical reason why localisation won't work so ended up using the following on values before they are passed to a template

def commify(n):
    if n is None: return None
    n = str(n)
    if '.' in n:
        dollars, cents = n.split('.')
    else:
        dollars, cents = n, None

    r = []
    for i, c in enumerate(str(dollars)[::-1]):
        if i and (not (i % 3)):
            r.insert(0, ',')
        r.insert(0, c)
    out = ''.join(r)
    if cents:
        out += '.' + cents
    return out
Community
  • 1
  • 1
Robert Johnstone
  • 5,431
  • 12
  • 58
  • 88