Why does floatformat:2 adds a comma after the hundred place

I have a Django project and I have a {{account.current_balance}} tag in my HTML. I also included the type of data it is just in case it matters. I understand #1 and #2, but I don't understand why with #3, adding intcomma would add a comma after the hundred place.

  1. Tag without floatformat or intcomma

    {{ account.current_balance }}

output:
Current Balance - Type
303.6000000000000 - Decimal

  1. Tag with floatformat:2

    {{ account.current_balance|floatformat:2 }}

output:
Current Balance - Type
303.60 - Decimal

  1. Tag with floatformat:2 with intcomma

    {{ account.current_balance|floatformat:2|intcomma }}

output:
Current Balance - Type
,303.60 - Decimal

This is a bug in Django having issue #35172. It has been solved for the LTS releases in versions 3.2.25+ and 4.2.11+, for the current major version it has been solved in version 5.0.3 onwards.

The solution to fix this would be to upgrade to a version of Django where this is fixed.

when using the intcomma filter along with floatformat filter in Django templates. The intcomma filter is used to add commas to large numbers for better readability, but it seems to be affecting the decimal portion of your number as well.

Tag without floatformat or intcomma

{{ account.current_balance }}

This simply outputs the current balance without any formatting applied.

Tag with floatformat

{{ account.current_balance|floatformat:2 }}

This applies the floatformat filter to round the number to 2 decimal places.

Tag with floatformat:2 with intcomma:

{{ account.current_balance|floatformat:2|intcomma }}

This applies both floatformat and intcomma filters. The floatformat filter rounds the number to 2 decimal places, and then the intcomma filter adds commas to the integer part of the number.

Back to Top