mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
fix: 修复 amis-formula ROUND FLOOR CEIL 的位数默认不是 2 问题 (#5171)
This commit is contained in:
parent
387e567a8d
commit
a0f4ba3344
@ -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', () => {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user