简体   繁体   中英

How to use dot as thousand separator in Django

In my settings.py I have following code:

LANGUAGE_CODE = 'en' 
USE_I18N = True    
USE_L10N = True
USE_DECIMAL_SEPARATOR = True
DECIMAL_SEPARATOR = ","
USE_THOUSAND_SEPARATOR = True
THOUSAND_SEPARATOR = "."

And in my template I use the number as follows:

{% load humanize %}
{% load i18n %}
{% load l10n %}
<div>{% trans "Price" %}: € <b>{{ payment|floatformat:2|intcomma }}</b></div>

But still the number is 18,300.00 and I want that it is 18.300,00 .

Any idea?

The following is noted in the documentation about DECIMAL_SEPARATOR setting:

Default: '.' (Dot)

Default decimal separator used when formatting decimal numbers.

Note that if USE_L10N is set to True , then the locale-dictated format has higher precedence and will be applied instead.

Since USE_L10N is set, the number format set for the locale is preferred when rendering a number.

As far as I know the current desired format for numbers isn't available in English language locale. I find that format in used in Deutsch language locale.

The language template tag allows you to switch language in templates .

{% load humanize %}
{% load i18n %}
{% load l10n %}
<div>{% trans "Price" %}: 
{% language 'de' %}
€ <b>{{ payment|floatformat:2|intcomma }}</b>
{% endlanguage %}
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM