changeset 75a4558f3a77 in sao:5.8
details: https://hg.tryton.org/sao?cmd=changeset;node=75a4558f3a77
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 0214b6f02291a797bc61c440711013f53cc4638b)
diffstat:
src/common.js | 15 +++++++++------
tests/sao.js | 4 +++-
2 files changed, 12 insertions(+), 7 deletions(-)
diffs (40 lines):
diff -r 28bbd53f524b -r 75a4558f3a77 src/common.js
--- a/src/common.js Mon Jan 11 00:11:25 2021 +0100
+++ b/src/common.js Mon Jan 18 23:29:44 2021 +0100
@@ -1989,13 +1989,16 @@
if (!value && value !== 0 && value !== new Sao.Decimal(0)) {
return '';
}
+ var digit = 0;
var factor = Number(field.factor || 1);
- var digit = String(value * factor)
- .replace(/0+$/, '').split('.')[1];
- if (digit) {
- digit = digit.length;
- } else {
- digit = 0;
+ var string = String(value * factor);
+ if (string.contains('e')) {
+ var exp = string.split('e')[1];
+ string = string.split('e')[0];
+ digit -= parseInt(exp);
+ }
+ if (string.contains('.')) {
+ digit += string.replace(/0+$/, '').split('.')[1].length;
}
return (value * factor).toFixed(digit);
};
diff -r 28bbd53f524b -r 75a4558f3a77 tests/sao.js
--- a/tests/sao.js Mon Jan 11 00:11:25 2021 +0100
+++ b/tests/sao.js Mon Jan 18 23:29:44 2021 +0100
@@ -1911,7 +1911,9 @@
[0, '0'],
[0.0, '0'],
[false, ''],
- [null, '']
+ [null, ''],
+ [1e-12, '0.000000000001'],
+ [1.0579e-10, '0.00000000010579'],
].forEach(test_func, field);
test_func.call({'type': 'float', 'factor': '100'}, [0.42, '42']);