diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 7a4defd392..8e25554aea 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -41,7 +41,7 @@ def intcomma(value, use_l10n=True): except (TypeError, ValueError): return intcomma(value, False) else: - return number_format(value) + return number_format(value, force_grouping=True) orig = force_unicode(value) new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig) if orig == new: diff --git a/django/utils/formats.py b/django/utils/formats.py index e176985791..2d8a813825 100644 --- a/django/utils/formats.py +++ b/django/utils/formats.py @@ -103,7 +103,7 @@ def time_format(value, format=None, use_l10n=None): """ return dateformat.time_format(value, get_format(format or 'TIME_FORMAT', use_l10n=use_l10n)) -def number_format(value, decimal_pos=None, use_l10n=None): +def number_format(value, decimal_pos=None, use_l10n=None, force_grouping=False): """ Formats a numeric value using localization settings @@ -120,6 +120,7 @@ def number_format(value, decimal_pos=None, use_l10n=None): decimal_pos, get_format('NUMBER_GROUPING', lang, use_l10n=use_l10n), get_format('THOUSAND_SEPARATOR', lang, use_l10n=use_l10n), + force_grouping=force_grouping ) def localize(value, use_l10n=None): diff --git a/django/utils/numberformat.py b/django/utils/numberformat.py index 9597cdd063..c6528c0167 100644 --- a/django/utils/numberformat.py +++ b/django/utils/numberformat.py @@ -2,7 +2,7 @@ from django.conf import settings from django.utils.safestring import mark_safe -def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep=''): +def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep='', force_grouping=False): """ Gets a number (as a number or string), and returns it as a string, using formats definied as arguments: @@ -13,7 +13,7 @@ def format(number, decimal_sep, decimal_pos=None, grouping=0, thousand_sep=''): * thousand_sep: Thousand separator symbol (for example ",") """ - use_grouping = settings.USE_L10N and \ + use_grouping = force_grouping or settings.USE_L10N and \ settings.USE_THOUSAND_SEPARATOR and grouping # Make the common case fast: if isinstance(number, int) and not use_grouping and not decimal_pos: