Commit 7dcdb461 authored by Jérome Perrin's avatar Jérome Perrin

float field was not rounding values when precision = 0


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24566 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b2110252
...@@ -1325,7 +1325,7 @@ class FloatWidget(TextWidget): ...@@ -1325,7 +1325,7 @@ class FloatWidget(TextWidget):
return value return value
try : try :
float_value = float(value) float_value = float(value)
if precision: if precision not in (None, ''):
float_value = round(float_value, precision) float_value = round(float_value, precision)
value = str(float_value) value = str(float_value)
except ValueError: except ValueError:
......
...@@ -105,6 +105,8 @@ class TestFloatField(unittest.TestCase): ...@@ -105,6 +105,8 @@ class TestFloatField(unittest.TestCase):
def test_format_precision(self): def test_format_precision(self):
self.field.values['precision'] = 0 self.field.values['precision'] = 0
self.assertEquals('12', self.widget.format_value(self.field, 12.34)) self.assertEquals('12', self.widget.format_value(self.field, 12.34))
# value is rounded
self.assertEquals('13', self.widget.format_value(self.field, 12.9))
purgeFieldValueCache() # call this before changing internal field values. purgeFieldValueCache() # call this before changing internal field values.
self.field.values['precision'] = 2 self.field.values['precision'] = 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment