Skip to content

Commit

Permalink
Fixed #35172 -- Fixed intcomma for string floats.
Browse files Browse the repository at this point in the history
Thanks Warwick Brown for the report.

Regression in 55519d6.
  • Loading branch information
felixxm committed Feb 7, 2024
1 parent 3e820d1 commit 9a3e1cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions django/contrib/humanize/templatetags/humanize.py
Expand Up @@ -80,6 +80,8 @@ def intcomma(value, use_l10n=True):
if match:
prefix = match[0]
prefix_with_commas = re.sub(r"\d{3}", r"\g<0>,", prefix[::-1])[::-1]
# Remove a leading comma, if needed.
prefix_with_commas = re.sub(r"^(-?),", r"\1", prefix_with_commas)
result = prefix_with_commas + result[len(prefix) :]
return result

Expand Down
4 changes: 3 additions & 1 deletion docs/releases/5.0.3.txt
Expand Up @@ -9,4 +9,6 @@ Django 5.0.3 fixes several bugs in 5.0.2.
Bugfixes
========

* ...
* Fixed a regression in Django 5.0.2 where the ``intcomma`` template filter
could return a leading comma for string representation of floats
(:ticket:`35172`).
12 changes: 12 additions & 0 deletions tests/humanize_tests/tests.py
Expand Up @@ -129,12 +129,18 @@ def test_intcomma(self):
-1234567.25,
"100",
"-100",
"100.1",
"-100.1",
"100.13",
"-100.13",
"1000",
"-1000",
"10123",
"-10123",
"10311",
"-10311",
"100000.13",
"-100000.13",
"1000000",
"-1000000",
"1234567.1234567",
Expand Down Expand Up @@ -163,12 +169,18 @@ def test_intcomma(self):
"-1,234,567.25",
"100",
"-100",
"100.1",
"-100.1",
"100.13",
"-100.13",
"1,000",
"-1,000",
"10,123",
"-10,123",
"10,311",
"-10,311",
"100,000.13",
"-100,000.13",
"1,000,000",
"-1,000,000",
"1,234,567.1234567",
Expand Down

0 comments on commit 9a3e1cf

Please sign in to comment.