fix(core): fix round bug in formula evaluator (#4070)

This commit is contained in:
Junyi 2024-04-17 18:40:26 +08:00 committed by GitHub
parent ac45742e34
commit 92b28fa411
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -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', () => {

View File

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