From 7dcdb46192a71e091c939141910ab389cbbd1c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Wed, 12 Nov 2008 17:59:40 +0000 Subject: [PATCH] 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 --- product/ERP5Form/FormulatorPatch.py | 2 +- product/ERP5Form/tests/testFields.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/product/ERP5Form/FormulatorPatch.py b/product/ERP5Form/FormulatorPatch.py index b6a2f0199d..67dd779809 100644 --- a/product/ERP5Form/FormulatorPatch.py +++ b/product/ERP5Form/FormulatorPatch.py @@ -1325,7 +1325,7 @@ class FloatWidget(TextWidget): return value try : float_value = float(value) - if precision: + if precision not in (None, ''): float_value = round(float_value, precision) value = str(float_value) except ValueError: diff --git a/product/ERP5Form/tests/testFields.py b/product/ERP5Form/tests/testFields.py index 06b62a871c..4d73191045 100644 --- a/product/ERP5Form/tests/testFields.py +++ b/product/ERP5Form/tests/testFields.py @@ -105,6 +105,8 @@ class TestFloatField(unittest.TestCase): def test_format_precision(self): self.field.values['precision'] = 0 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. self.field.values['precision'] = 2 -- 2.30.9