mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-03 12:47:44 +08:00
fix(core): fix round bug in formula evaluator (#4070)
This commit is contained in:
parent
ac45742e34
commit
92b28fa411
@ -145,6 +145,16 @@ describe('evaluate', () => {
|
||||
const result = formulaEval('{{a.1a}}', { a: { '1a': 1 } });
|
||||
expect(result).toBe(1);
|
||||
});
|
||||
|
||||
it('number greater than 32bit integer', () => {
|
||||
const result = formulaEval('{{a}}', { a: 1609459200000 });
|
||||
expect(result).toBe(1609459200000);
|
||||
});
|
||||
|
||||
it('ISO date string parsing by Date.parse', () => {
|
||||
const result = formulaEval('Date.parse({{a}})', { a: '2021-01-01T00:00:00.000Z' });
|
||||
expect(result).toBe(1609459200000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('string', () => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as functions from '@formulajs/formulajs';
|
||||
import { round } from 'mathjs';
|
||||
|
||||
import { evaluate } from '.';
|
||||
|
||||
@ -12,7 +13,7 @@ export default evaluate.bind(function (expression: string, scope = {}) {
|
||||
if (Number.isNaN(result) || !Number.isFinite(result)) {
|
||||
return null;
|
||||
}
|
||||
return functions.ROUND(result, 9);
|
||||
return round(result, 9);
|
||||
}
|
||||
return result;
|
||||
}, {});
|
||||
|
Loading…
Reference in New Issue
Block a user