fix(evaluator): fix round decimal places (#6492)

This commit is contained in:
Junyi 2025-03-18 15:21:50 +08:00 committed by GitHub
parent 7da1c200ed
commit fa5890cea5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 2 deletions

View File

@ -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);
});
});

View File

@ -13,4 +13,8 @@ describe('evaluators > mathjs', () => {
it('matrix type should be to array', () => { it('matrix type should be to array', () => {
expect(mathjs('range(1, 3, 1)')).toEqual([1, 2, 3]); expect(mathjs('range(1, 3, 1)')).toEqual([1, 2, 3]);
}); });
it('precision should be 9', () => {
expect(mathjs('100*2.3')).toBe(230);
});
}); });

View File

@ -22,7 +22,7 @@ export default evaluate.bind(function (expression: string, scope = {}) {
if (Number.isNaN(result) || !Number.isFinite(result)) { if (Number.isNaN(result) || !Number.isFinite(result)) {
return null; return null;
} }
return round(result, 14); return round(result, 9);
} }
return result; return result;
}, {}); }, {});

View File

@ -18,7 +18,7 @@ export default evaluate.bind(
if (Number.isNaN(result) || !Number.isFinite(result)) { if (Number.isNaN(result) || !Number.isFinite(result)) {
return null; return null;
} }
return math.round(result, 14); return math.round(result, 9);
} }
if (result instanceof math.Matrix) { if (result instanceof math.Matrix) {
return result.toArray(); return result.toArray();