diff --git a/opentreemap/treemap/audit.py b/opentreemap/treemap/audit.py
index 424ee036b..8762e68ae 100644
--- a/opentreemap/treemap/audit.py
+++ b/opentreemap/treemap/audit.py
@@ -30,7 +30,7 @@
to_object_name, safe_get_model_class,
get_pk_from_collection_audit_name,
get_name_from_canonical_name,
- make_udf_name_from_key)
+ make_udf_name_from_key, num_format)
from treemap.decorators import classproperty
from treemap.lib.object_caches import (field_permissions,
@@ -1480,6 +1480,8 @@ def _unit_format(self, value):
units = get_unit_name(get_units(self.instance,
model_name, self.field))
value += (' %s' % units)
+ elif isinstance(value, float):
+ return num_format(value)
return value
diff --git a/opentreemap/treemap/templates/treemap/field/attrs.html b/opentreemap/treemap/templates/treemap/field/attrs.html
index cb3228960..77128bf2f 100644
--- a/opentreemap/treemap/templates/treemap/field/attrs.html
+++ b/opentreemap/treemap/templates/treemap/field/attrs.html
@@ -1,7 +1,12 @@
{% load l10n %}
+{% load util %}
data-field="{{ field.identifier }}"
data-class="{{ class }}"
+{% if field.data_type == 'float' %}
+data-value="{{ field.value|num_format|default_if_none:""|unlocalize|force_escape }}"
+{% else %}
data-value="{{ field.value|default_if_none:""|unlocalize|force_escape }}"
+{% endif %}
data-type="{{ field.data_type }}"
data-units="{{ field.units }}"
data-digits="{{ field.digits }}"
diff --git a/opentreemap/treemap/templates/treemap/field/inputs.html b/opentreemap/treemap/templates/treemap/field/inputs.html
index 6a2cc5874..8c3c3f740 100644
--- a/opentreemap/treemap/templates/treemap/field/inputs.html
+++ b/opentreemap/treemap/templates/treemap/field/inputs.html
@@ -43,7 +43,11 @@
{{ field.units }}
diff --git a/opentreemap/treemap/templatetags/form_extras.py b/opentreemap/treemap/templatetags/form_extras.py
index 6ff37ca87..ec4da9ad7 100644
--- a/opentreemap/treemap/templatetags/form_extras.py
+++ b/opentreemap/treemap/templatetags/form_extras.py
@@ -17,7 +17,7 @@
from opentreemap.util import dotted_split
-from treemap.util import get_model_for_instance, to_object_name
+from treemap.util import get_model_for_instance, to_object_name, num_format
from treemap.json_field import (is_json_field_reference,
get_attr_from_json_field)
from treemap.units import (get_digits_if_formattable, get_units_if_convertible,
@@ -430,6 +430,8 @@ def _field_value(model, field_name, data_type):
display_vals = [choice['display_value'] for choice in choices
if choice['value'] == field_value]
display_val = display_vals[0] if display_vals else field_value
+ elif data_type == 'float':
+ display_val = num_format(field_value)
else:
display_val = unicode(field_value)
diff --git a/opentreemap/treemap/templatetags/util.py b/opentreemap/treemap/templatetags/util.py
index 1b0a6bfcd..50f14c526 100644
--- a/opentreemap/treemap/templatetags/util.py
+++ b/opentreemap/treemap/templatetags/util.py
@@ -10,7 +10,7 @@
from treemap.models import MapFeature, Tree, TreePhoto, MapFeaturePhoto, Audit
from treemap.udf import UserDefinedCollectionValue
from treemap.util import (get_filterable_audit_models, to_model_name,
- safe_get_model_class)
+ safe_get_model_class, num_format as util_num_format)
from treemap.units import Convertible
@@ -199,3 +199,8 @@ def udf_name(udf_identifier):
raise ValueError('Unrecognized identifier %(id)s' % udf_identifier)
return udf_identifier.split("udf:", 1)[1]
+
+
+@register.filter
+def num_format(num):
+ return util_num_format(num)
diff --git a/opentreemap/treemap/util.py b/opentreemap/treemap/util.py
index be0f4d845..e2ffc1d0c 100644
--- a/opentreemap/treemap/util.py
+++ b/opentreemap/treemap/util.py
@@ -231,3 +231,10 @@ def make_udf_name_from_key(key):
def make_udf_lookup_from_key(key):
return 'udfs__{}'.format(key)
+
+
+def num_format(num):
+ if isinstance(num, float):
+ # Allow for up to 10 digits of precision, but strip trailing '0' or '.'
+ return '{0:.10f}'.format(num).rstrip('0').rstrip('.')
+ return num