views:

45

answers:

2

Hi everyone, i just can't seem to find a definitive answer to this issue, and django's irc needs auth to services... So my question is : how can you force some kind of formatting for FloatFields in template when you're using Django ?

The problem is simple i need simple dot separated numbers like this : 42547.34 And i end up with comma separated values...

here is a example of template where the problem occurs :

{% for point in zone.points.all  %}
  {% if forloop.last %}
    new google.maps.LatLng({{point.latitude|floatformat}},{{point.longitude|floatformat}})
  {% else %} 
    new google.maps.LatLng({{point.latitude|floatformat}},{{point.longitude|floatformat}}),
  {% endif %}
{% endfor %}];

Thank you for your time.

P.S. i don't have this problem when using the admin generated forms where the floats appear correctly (My locale is en_US)

+1  A: 

You could use a custom formats.py (see "Creating custom format files" in the Django docs) and define THOUSAND_SEPARATOR and DECIMAL_SEPARATOR

THOUSAND_SEPARATOR = ''
DECIMAL_SEPARATOR = '.'

This is a global setting, so it will affect all floats displayed on your site. And you'll have to turn on localization (USE_L10N in your settings.py).

If you have control over the template, you could simply remove the floatformat filter.

edit: I'm not sure, but perhaps you are a victim of this Django bug: #13617. Try to turn off localization support in your settings.py and see if the erroneous commas disappear:

USE_L10N = False

If that is the case, have a look at the various workarounds mentioned in the bugreport (the simplest being to turn localization off if you don't need it anyway).

piquadrat
thank you for your answer, but simply removing the filter "floatformat" doesn't work... Should i add another filter ?
ssaboum
+1  A: 

I've got the same issue, and as piquadrat says, it's an annoying bug related to localization support. Changing USE_L10N = True to False solve this, it is suppposed to be fix in Django 1.3.

aldeano