changeset 0214b6f02291 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=0214b6f02291
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:
src/common.js | 15 +++++++++------
tests/sao.js | 4 +++-
2 files changed, 12 insertions(+), 7 deletions(-)
diffs (40 lines):
diff -r 497c0f50732a -r 0214b6f02291 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
@@ -1991,13 +1991,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 497c0f50732a -r 0214b6f02291 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']);