changeset a8eec0bd53ed in tryton:default details: https://hg.tryton.org/tryton?cmd=changeset;node=a8eec0bd53ed 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 diffstat: tryton/common/domain_parser.py | 11 +++++++---- tryton/tests/test_common_domain_parser.py | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diffs (38 lines): diff -r 0a8e146b547b -r a8eec0bd53ed 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 @@ -313,15 +313,18 @@ and (not isinstance(value, (int, float, Decimal)) or isinstance(value, bool))): 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) diff -r 0a8e146b547b -r a8eec0bd53ed tryton/tests/test_common_domain_parser.py --- a/tryton/tests/test_common_domain_parser.py Mon Jan 11 00:08:50 2021 +0100 +++ b/tryton/tests/test_common_domain_parser.py Mon Jan 18 23:29:44 2021 +0100 @@ -288,6 +288,8 @@ (0.0, '0'), (False, ''), (None, ''), + (1e-12, '0.000000000001'), + (1.0579e-10, '0.00000000010579'), ): self.assertEqual( format_value(field, value), result,