简体   繁体   English

如何在Django中将点用作千位分隔符

[英]How to use dot as thousand separator in Django

In my settings.py I have following code: 在我的settings.py我有以下代码:

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 . 但仍然是18,300.00 ,我希望它是18.300,00

Any idea? 任何想法?

The following is noted in the documentation about DECIMAL_SEPARATOR setting: 关于DECIMAL_SEPARATOR设置的文档中记录了以下内容

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. 请注意,如果USE_L10N设置为TrueUSE_L10N区域设置指定的格式具有更高的优先级,并且将被应用。

Since USE_L10N is set, the number format set for the locale is preferred when rendering a number. 由于设置了USE_L10N ,因此在呈现数字时,首选为语言环境设置的数字格式。

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. 我发现该格式在Deutsch语言区域中使用。

The language template tag allows you to switch language in templates . language模板标签允许您在模板中切换语言

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在python2.7中使用DOT作为千位分隔符 - Using DOT as thousand separator in python2.7 千位分隔符未在Django管理中应用 - Thousand separator not applied in Django admin 如何将千位分隔符添加到 Javascript / Python / Django 中的数字 - How to add Thousand Separator to number in Javascript / Python / Django 如何更改 django rest 框架中序列化程序中使用的 DECIMAL_SEPARATOR 和 THOUSAND_SEPARATOR? - How to change DECIMAL_SEPARATOR and THOUSAND_SEPARATOR used in serializers in django rest framework? 在matplotlib中,如何将千位分隔符设置为单引号? - In matplotlib, how to set the thousand separator to be a single quote? 如何处理小数点和千位分隔符的逗号 - How to deal with commas for decimal AND thousand separator 如何删除元组列表中的千位分隔符? - How to remove thousand separator in a list of tuple? 如何在 Jinja 中格式化十进制千位分隔符 - How to format decimal thousand separator in Jinja 如何将十进制和千位分隔符应用于cbar中的数字? - How to apply decimal and thousand separator to numbers in cbar? 如何使用逗号分隔符和逗号分隔符读取熊猫CSV文件 - How to read pandas CSV file with comma separator and comma thousand separator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM