Formatting Django decimal number template

Asked

Viewed 593 times

1

I’m having trouble displaying the results of a calculation. I have a Decimalfield and want to return it formatted this way:

1.000.000,00

If I order to display normally without tags, it looks like this:

1000000,00

If I add {{value|floatformat:2}} looks the same:

1000000,00

If I load humanize and add an intcomma ({{value|floatformat:2|intcomma}} gets like this:

1,000,000,00

I don’t know how to solve this problem. Man settings.py is that way:

LANGUAGE_CODE = 'pt-BR'

TIME_ZONE = 'America/Sao_Paulo'

USE_I18N = True

USE_L10N = True

USE_TZ = True

1 answer

2


Add in Settings (considering your other settings, no need for humanize):

THOUSAND_SEPARATOR='.',
USE_THOUSAND_SEPARATOR=True

In the template:

{% load l10n %}

...

{{valor | floatformat:2}}

Example of an output where I take the typed value and multiply by 2:

inserir a descrição da imagem aqui

  • 1

    Solved, thanks! It just wasn’t necessary to load the l10n because the floatformat is standard of the Django template if I’m not mistaken.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.