fix: 修复 amis-formula ROUND FLOOR CEIL 的位数默认不是 2 问题 (#5171)

This commit is contained in:
吴多益 2022-08-23 10:21:50 +08:00 committed by GitHub
parent 387e567a8d
commit a0f4ba3344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -88,7 +88,10 @@ test('formula:ifs', () => {
expect(!!evalFormual('IFS(0, 1, 2)')).toBe(true);
expect(!!evalFormual('IFS(0, 1, 2, 2, 3)')).toBe(true);
expect(!!evalFormual('IFS(0, 1, 0, 2, 0)')).toBe(false);
expect(evalFormual('IFS(0, 1, 2, 2)')).toBe(2);
expect(evalFormual('IFS(0, 1, 0, 2)')).toBe(undefined);
});
test('formula:math', () => {
expect(evalFormual('ABS(1)')).toBe(1);
expect(evalFormual('ABS(-1)')).toBe(1);
@ -101,12 +104,12 @@ test('formula:math', () => {
expect(evalFormual('PI()')).toBe(Math.PI);
expect(evalFormual('ROUND(3.5)')).toBe(4);
expect(evalFormual('ROUND(3.4)')).toBe(3);
expect(evalFormual('ROUND(3.55)')).toBe(3.55);
expect(evalFormual('ROUND(3.45)')).toBe(3.45);
expect(evalFormual('ROUND(3.456789, 2)')).toBe(3.46);
expect(evalFormual('CEIL(3.456789)')).toBe(4);
expect(evalFormual('FLOOR(3.456789)')).toBe(3);
expect(evalFormual('CEIL(3.456789)')).toBe(3.46);
expect(evalFormual('FLOOR(3.456789)')).toBe(3.45);
expect(evalFormual('SQRT(4)')).toBe(2);
expect(evalFormual('AVG(4, 6, 10, 10, 10)')).toBe(8);
@ -128,6 +131,7 @@ test('formula:math', () => {
expect(evalFormual('"3" + "3"')).toBe(6);
expect(evalFormual('"3" - "3"')).toBe(0);
expect(evalFormual('AVG(4, "6", "10", 10, 10)')).toBe(8);
expect(evalFormual('MAX(4, "6", "10", 2, 3)')).toBe(10);
});
test('formula:text', () => {

View File

@ -690,7 +690,7 @@ export class Evaluator {
*
* @returns {number}
*/
fnROUND(a: number, b: number) {
fnROUND(a: number, b: number = 2) {
a = this.formatNumber(a);
b = this.formatNumber(b);
const bResult = Math.round(b);
@ -713,7 +713,7 @@ export class Evaluator {
*
* @returns {number}
*/
fnFLOOR(a: number, b: number) {
fnFLOOR(a: number, b: number = 2) {
a = this.formatNumber(a);
b = this.formatNumber(b);
const bResult = Math.round(b);
@ -736,7 +736,7 @@ export class Evaluator {
*
* @returns {number}
*/
fnCEIL(a: number, b: number) {
fnCEIL(a: number, b: number = 2) {
a = this.formatNumber(a);
b = this.formatNumber(b);
const bResult = Math.round(b);