From af655e61677702c9ccbd418e53407b1b397e7916 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 23 Apr 2010 14:27:16 +0000
Subject: [PATCH] if precision is defined on the field, use this precision to
 format; only use repr if no precision is defined. If number is so big that it
 can only be displayed in scientific notation, return it as is.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34755 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/Formulator/Widget.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/product/Formulator/Widget.py b/product/Formulator/Widget.py
index 526a69a0fe..14d75f2c7c 100644
--- a/product/Formulator/Widget.py
+++ b/product/Formulator/Widget.py
@@ -1649,11 +1649,17 @@ class FloatWidget(TextWidget):
       try :
         float_value = float(value)
         if precision not in (None, ''):
-          float_value = round(float_value, precision)
-        # we use repr that have a better precision than str
-        value = repr(float_value)
+          # if we have a precision, then use it now
+          value = ('%%0.%sf' % precision) % float_value
+        else:
+          # if no precision, we use repr which have a better precision than str
+          value = repr(float_value)
       except ValueError:
         return value
+      # if this number displayed in scientific notification, just return it as
+      # is
+      if 'e' in value:
+        return value
       value_list = value.split('.')
       integer = value_list[0]
       
-- 
2.30.9