Home > Enterprise >  display commas instead of periods
display commas instead of periods

Time:11-21

in my sql table I have decimal data with dot as a separator but the display in my page is done with commas

I would like to display them with dot

in my settings i have this

LANGUAGE_CODE = "fr-fr"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True

my models

class VilleStation(models.Model):
    nomVille = models.CharField(max_length=255)
    adresse = models.CharField(max_length=255)
    cp = models.CharField(max_length=5)
    latitude = models.DecimalField(max_digits=9, decimal_places=6)
    longitude = models.DecimalField(max_digits=9, decimal_places=6)

in the templates i have this

{% for c in object_list %}                
{{c.nomVille}}
{{c.adresse}}
{{c.cp}}
{{c.latitude}}
{{c.longitude}}
{% endfor %}

thank

CodePudding user response:

Decimal separator is controlled by two settings in Django settings:

First one is DECIMAL_SEPARATOR (Default: '.')

https://docs.djangoproject.com/en/4.1/ref/settings/#decimal-separator

And second one: USE_L10N (Default: True)

https://docs.djangoproject.com/en/4.1/ref/settings/#use-l10n

in your case use USE_L10N=False

CodePudding user response:

Give this a whirl, as per the docs, you can turn off number localisation like so:

{{  value|floatformat:"3u"  }}

What does the docs say?

Output is always localized (independently of the {% localize off %} tag) unless the argument passed to floatformat has the u suffix, which will force disabling localization.

Be aware of the following note further down the page:

Changed in Django 4.0: floatformat template filter no longer depends on the USE_L10N setting and always returns localized output.

And subsequently:

The u suffix to force disabling localization was added

Please see the documentation regarding the floatformat template tag

  • Related