I am using python 2.6 and django 1.27
my model
class Plan(models.Model):
price = models.DecimalField(max_digits=5, decimal_places=2,default=0)
.....
in my template i have
{{plan.price}}
My problem is that on my local machine i get dot used as separator for example '2.54'
While on my production machine i get '2,54' - comma is used as separator.
I would like it to use dot everywhere.
in the django docs
https://docs.djangoproject.com/en/1.2/ref/settings/#decimal-separator
it say there is the "DECIMAL_SEPARATOR" option the default it dot.
btw in both machines
In [2]: from django.conf import settings
In [3]: print settings.DECIMAL_SEPARATOR
.
SOLUTION:
as @Marcin pointed out
setting USE_L10N to False on production machine.
as a separator between the dollars and cents. Some countries use a comma (,) instead of a decimal to indicate that separation. In addition, while the U.S. and a number of other countries use a comma to separate thousands, some countries use a decimal point for this purpose.
In the United States, we use the decimal or period (“.”) to represent the difference between whole numbers and partial numbers. We use the comma (“,”) to separate groups of three places on the whole numbers side. This might be different from the way you currently write numbers.
In German the comma rather than the period is used as a decimal separator and the dot is used as a thousands separator: 12.345,67 . The comma creates some unwanted space when used as in $12.345,67$ .
You can use this alternative way directly on your template:
{% load l10n %}
{% localize off %}
{{ my_floatvar }}
{% endlocalize %}
or this one:
{% load l10n %}
{{ my_floatvar|unlocalize }}
More info in https://docs.djangoproject.com/en/dev/topics/i18n/formatting/#controlling-localization-in-templates
First of all, I assume you have L10N and I18N turned on in your settings.py
, because that's the default. The difference you see is likely because you are accessing the website from two different computers with two different locales. Django tries to format things for the locale reported by the browser.
However, you can disable this behaviour. See https://docs.djangoproject.com/en/dev/ref/settings/. Set USE_L10N=False
, and set the various separator options specified on the linked page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With