Ticket #3017: commaseparate.patch

File commaseparate.patch, 1.9 KB (added by SmileyChris, 8 years ago)
  • django/contrib/humanize/templatetags/humanize.py

     
    1818    return '%d%s' % (value, t[value % 10])
    1919register.filter(ordinal)
    2020
    21 def intcomma(value):
     21def commaseparate(value):
    2222    """
    23     Converts an integer to a string containing commas every three digits.
     23    Converts an number to a string containing commas every three digits.
    2424    For example, 3000 becomes '3,000' and 45000 becomes '45,000'.
    2525    """
    2626    orig = str(value)
    27     new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', str(value))
     27    new = re.sub("^(-?\d+)(\d{3})((?:\.\d+)?)", r'\1,\2\3', str(value))
    2828    if orig == new:
    2929        return new
    3030    else:
    3131        return intcomma(new)
     32register.filter(commaseparate)
     33
     34# Backwards compatibility (commaseparate used to be called intcomma).
     35intcomma = commaseparate
    3236register.filter(intcomma)
    3337
    3438def intword(value):
  • docs/add_ons.txt

     
    7070
    7171You can pass in either an integer or a string representation of an integer.
    7272
    73 intcomma
    74 --------
     73commaseparate
     74-------------
    7575
    76 Converts an integer to a string containing commas every three digits.
     76Converts a number to a string containing commas every three digits (before any
     77decimal place).
    7778
    7879Examples:
    7980
     
    8182    * ``45000`` becomes ``'45,000'``.
    8283    * ``450000`` becomes ``'450,000'``.
    8384    * ``4500000`` becomes ``'4,500,000'``.
     85    * ``4500.0001`` becomes ``'4,500.0001'``.
    8486
    85 You can pass in either an integer or a string representation of an integer.
     87You can pass in either an integer, a float or a string representation of an
     88integer or float.
    8689
    8790intword
    8891-------
Back to Top