changeset 93e2e0c28f62 in sao:5.0
details: https://hg.tryton.org/sao?cmd=changeset;node=93e2e0c28f62
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 e9c32f59a26f -r 93e2e0c28f62 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
@@ -1915,13 +1915,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 e9c32f59a26f -r 93e2e0c28f62 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
@@ -1579,7 +1579,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']);