changeset 2ddaef9bf855 in tryton:5.0
details: https://hg.tryton.org/tryton?cmd=changeset;node=2ddaef9bf855
description:
        Support float represented by exponential

        The domain parser need to find the number of digit to display by 
analysing the
        string format of the value. Some small values may be formatted as 
exponential.

        issue9955
        review347261002
        (grafted from a8eec0bd53ed6c82579f3c34e9752d300c1b0f0a)
diffstat:

 tryton/common/domain_parser.py |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (26 lines):

diff -r cdf5b7b768cf -r 2ddaef9bf855 tryton/common/domain_parser.py
--- a/tryton/common/domain_parser.py    Mon Jan 11 00:08:50 2021 +0100
+++ b/tryton/common/domain_parser.py    Mon Jan 18 23:29:44 2021 +0100
@@ -502,15 +502,18 @@
                 and value is not 0
                 and not isinstance(value, (float, Decimal))):
             return ''
+        digit = 0
         if isinstance(value, Decimal):
             cast = Decimal
         else:
             cast = float
         factor = cast(field.get('factor', 1))
-        try:
-            digit = len(str(value * factor).rstrip('0').split('.')[1])
-        except IndexError:
-            digit = 0
+        string_ = str(value * factor)
+        if 'e' in string_:
+            string_, exp = string_.split('e')
+            digit -= int(exp)
+        if '.' in string_:
+            digit += len(string_.rstrip('0').split('.')[1])
         return locale.localize(
             '{0:.{1}f}'.format(value * factor or 0, digit), True)
 

Reply via email to