Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

19282 intcomma #785

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+7 −6
Split
@@ -1,7 +1,7 @@
from __future__ import unicode_literals
import re
from datetime import date, datetime
-
+from decimal import Decimal
from django import template
from django.conf import settings
from django.template import defaultfilters
@@ -35,7 +35,7 @@ def intcomma(value, use_l10n=True):
"""
if settings.USE_L10N and use_l10n:
try:
- if not isinstance(value, float):
+ if not isinstance(value, float) and not isinstance(value, Decimal):
value = int(value)
except (TypeError, ValueError):
return intcomma(value, False)
@@ -17,6 +17,7 @@
from django.utils.translation import ugettext as _
from django.utils import tzinfo
from django.utils.unittest import skipIf
+from decimal import Decimal
# Mock out datetime in some tests so they don't fail occasionally when they
@@ -58,20 +59,20 @@ def test_ordinal(self):
def test_intcomma(self):
test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
- '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
+ '100', '1000', '10123', '10311', '1000000', '1234567.1234567', Decimal('1234567.1234567'),
None)
result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
- '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
+ '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
None)
self.humanize_tester(test_list, result_list, 'intcomma')
def test_l10n_intcomma(self):
test_list = (100, 1000, 10123, 10311, 1000000, 1234567.25,
- '100', '1000', '10123', '10311', '1000000', '1234567.1234567',
+ '100', '1000', '10123', '10311', '1000000', '1234567.1234567', Decimal('1234567.1234567'),
None)
result_list = ('100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.25',
- '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567',
+ '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
None)
with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False):