PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] Why django uses a comma as decimal separator

 August 11, 2022     decimal, django, python     No comments   

Issue

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.


Solution

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.



Answered By - Marcin
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing