Skip to content

Commit fc41af6

Browse files
committed
[3.2.x] Fixed #35172 -- Fixed intcomma for string floats.
Thanks Warwick Brown for the report. Regression in 55519d6. Backport of 2f14c2c from main.
1 parent b9170b4 commit fc41af6

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

django/contrib/humanize/templatetags/humanize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def intcomma(value, use_l10n=True):
7575
if match:
7676
prefix = match[0]
7777
prefix_with_commas = re.sub(r"\d{3}", r"\g<0>,", prefix[::-1])[::-1]
78+
# Remove a leading comma, if needed.
79+
prefix_with_commas = re.sub(r"^(-?),", r"\1", prefix_with_commas)
7880
result = prefix_with_commas + result[len(prefix) :]
7981
return result
8082

docs/releases/3.2.25.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
===========================
2+
Django 3.2.25 release notes
3+
===========================
4+
5+
*Expected March 4, 2024*
6+
7+
Django 3.2.25 fixes a regression in 3.2.24.
8+
9+
Bugfixes
10+
========
11+
12+
* Fixed a regression in Django 3.2.24 where ``intcomma`` template filter could
13+
return a leading comma for string representation of floats (:ticket:`35172`).

docs/releases/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ versions of the documentation contain the release notes for any later releases.
2525
.. toctree::
2626
:maxdepth: 1
2727

28+
3.2.25
2829
3.2.24
2930
3.2.23
3031
3.2.22

tests/humanize_tests/tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ def test_intcomma(self):
8080
-1234567.25,
8181
"100",
8282
"-100",
83+
"100.1",
84+
"-100.1",
85+
"100.13",
86+
"-100.13",
8387
"1000",
8488
"-1000",
8589
"10123",
8690
"-10123",
8791
"10311",
8892
"-10311",
93+
"100000.13",
94+
"-100000.13",
8995
"1000000",
9096
"-1000000",
9197
"1234567.1234567",
@@ -114,12 +120,18 @@ def test_intcomma(self):
114120
"-1,234,567.25",
115121
"100",
116122
"-100",
123+
"100.1",
124+
"-100.1",
125+
"100.13",
126+
"-100.13",
117127
"1,000",
118128
"-1,000",
119129
"10,123",
120130
"-10,123",
121131
"10,311",
122132
"-10,311",
133+
"100,000.13",
134+
"-100,000.13",
123135
"1,000,000",
124136
"-1,000,000",
125137
"1,234,567.1234567",

0 commit comments

Comments
 (0)