diff --git a/product/ERP5Form/FormulatorPatch.py b/product/ERP5Form/FormulatorPatch.py index 3d478388dd394c679c51fe8ffc013b05805f4bc2..df4d50754fd8ef5713535e79cfea473c06da80f8 100644 --- a/product/ERP5Form/FormulatorPatch.py +++ b/product/ERP5Form/FormulatorPatch.py @@ -1059,10 +1059,11 @@ class FloatWidget(TextWidget): if input_style.find('%')>=0: percent=1 value = float(value) * 100 - if precision: - value = round(value, precision) try : - value = str(float(value)) + float_value = float(value) + if precision: + float_value = round(float_value, precision) + value = str(float_value) except ValueError: return value else: diff --git a/product/ERP5Form/tests/testFields.py b/product/ERP5Form/tests/testFields.py index 17f9df5c31c9a10462aae1bd475c98cc293ef465..026ba95ca3ef49fa8aff53748edac84c3b8a20de 100644 --- a/product/ERP5Form/tests/testFields.py +++ b/product/ERP5Form/tests/testFields.py @@ -60,12 +60,18 @@ class TestFloatField(unittest.TestCase): self.assertEquals('0.01', self.widget.format_value(self.field, 0.011)) # value is rounded self.assertEquals('0.01', self.widget.format_value(self.field, 0.009999)) - + def test_render_view(self): self.field.values['input_style'] = '-1 234.5' self.field.values['precision'] = 2 self.field.values['editable'] = 0 self.assertEquals('1 000.00', self.field.render(1000)) + + def test_render_string_value(self): + self.field.values['precision'] = 2 + self.field.values['editable'] = 0 + self.assertEquals('12.34', self.field.render("12.34")) + self.assertEquals('not float', self.field.render("not float")) def test_render_big_numbers(self): self.field.values['precision'] = 2