mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 05:29:26 +08:00
fix(evaluator): fix round decimal places (#6492)
This commit is contained in:
parent
7da1c200ed
commit
fa5890cea5
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* This file is part of the NocoBase (R) project.
|
||||
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||
* Authors: NocoBase Team.
|
||||
*
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import formulajs from '../formulajs';
|
||||
|
||||
describe('evaluators > formulajs', () => {
|
||||
it('add new line in string', () => {
|
||||
expect(formulajs(`CONCATENATE('a', '\\n', 'b')`)).toBe('a\nb');
|
||||
});
|
||||
|
||||
it('calculate null with number', () => {
|
||||
expect(formulajs('null + 1')).toBe(1);
|
||||
});
|
||||
|
||||
it('precision should be 9', () => {
|
||||
expect(formulajs('100*2.3')).toBe(230);
|
||||
});
|
||||
});
|
@ -13,4 +13,8 @@ describe('evaluators > mathjs', () => {
|
||||
it('matrix type should be to array', () => {
|
||||
expect(mathjs('range(1, 3, 1)')).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('precision should be 9', () => {
|
||||
expect(mathjs('100*2.3')).toBe(230);
|
||||
});
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ export default evaluate.bind(function (expression: string, scope = {}) {
|
||||
if (Number.isNaN(result) || !Number.isFinite(result)) {
|
||||
return null;
|
||||
}
|
||||
return round(result, 14);
|
||||
return round(result, 9);
|
||||
}
|
||||
return result;
|
||||
}, {});
|
||||
|
@ -18,7 +18,7 @@ export default evaluate.bind(
|
||||
if (Number.isNaN(result) || !Number.isFinite(result)) {
|
||||
return null;
|
||||
}
|
||||
return math.round(result, 14);
|
||||
return math.round(result, 9);
|
||||
}
|
||||
if (result instanceof math.Matrix) {
|
||||
return result.toArray();
|
||||
|
Loading…
x
Reference in New Issue
Block a user