changeset d5d391df26af in sao:5.6
details: https://hg.tryton.org/sao?cmd=changeset;node=d5d391df26af
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 f3df0f1369e6 -r d5d391df26af 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
@@ -1966,13 +1966,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 f3df0f1369e6 -r d5d391df26af 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
@@ -1793,7 +1793,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']);