From 430a50ed710224b0afbda464954dd983a502f950 Mon Sep 17 00:00:00 2001 From: Wonkeun No Date: Fri, 14 Oct 2022 14:32:44 -0400 Subject: [PATCH 1/4] Add an argument to ROUND func to show decimal numbers --- packages/nc-gui/utils/formulaUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/utils/formulaUtils.ts b/packages/nc-gui/utils/formulaUtils.ts index 63b89a94e2..9b084ce6b0 100644 --- a/packages/nc-gui/utils/formulaUtils.ts +++ b/packages/nc-gui/utils/formulaUtils.ts @@ -176,12 +176,12 @@ const formulas: Record = { type: formulaTypes.NUMERIC, validation: { args: { - rqd: 1, + rqd: 2, }, }, - description: 'Nearest integer to the input parameter', - syntax: 'ROUND(value)', - examples: ['ROUND(3.1415) => 3', 'ROUND({column1})'], + description: 'Rounded number to a specified number of decimal places', + syntax: 'ROUND(value, decimals)', + examples: ['ROUND(3.1415,2) => 3.14', 'ROUND({column1}, 3)'], }, MOD: { type: formulaTypes.NUMERIC, From 9267e95fbbdb5a009c03e653cbd62424039b4c31 Mon Sep 17 00:00:00 2001 From: Wonkeun No Date: Sun, 23 Oct 2022 23:11:17 -0400 Subject: [PATCH 2/4] feat(formulaUtils):allow decimal for round This allows ROUND func to have an optional parameter to show decimal number to the position that the integer parameter specifies This will address issue-3441 --- packages/nc-gui/utils/formulaUtils.ts | 9 ++++--- .../integration/common/3b_formula_column.js | 25 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/packages/nc-gui/utils/formulaUtils.ts b/packages/nc-gui/utils/formulaUtils.ts index 9b084ce6b0..ca35cac3ac 100644 --- a/packages/nc-gui/utils/formulaUtils.ts +++ b/packages/nc-gui/utils/formulaUtils.ts @@ -176,12 +176,13 @@ const formulas: Record = { type: formulaTypes.NUMERIC, validation: { args: { - rqd: 2, + min: 1, + max: 2, }, }, - description: 'Rounded number to a specified number of decimal places', - syntax: 'ROUND(value, decimals)', - examples: ['ROUND(3.1415,2) => 3.14', 'ROUND({column1}, 3)'], + description: 'Rounded number to a specified number of decimal places or the nearest integer if not specified', + syntax: 'ROUND(value, length), ROUND(value)', + examples: ['ROUND(3.1415,2) => 3.14', 'ROUND(3.1415) => 3', 'ROUND({column1}, 3)'], }, MOD: { type: formulaTypes.NUMERIC, diff --git a/scripts/cypress/integration/common/3b_formula_column.js b/scripts/cypress/integration/common/3b_formula_column.js index dbe38a890d..baceff2f0d 100644 --- a/scripts/cypress/integration/common/3b_formula_column.js +++ b/scripts/cypress/integration/common/3b_formula_column.js @@ -146,9 +146,10 @@ export const genTest = (apiType, dbType) => { let RESULT_MATH_0 = []; let RESULT_MATH_1 = []; let RESULT_MATH_2 = []; + let RESULT_MATH_3 = []; let RESULT_WEEKDAY_0 = []; let RESULT_WEEKDAY_1 = []; - + for (let i = 0; i < 10; i++) { // CONCAT, LOWER, UPPER, TRIM RESULT_STRING[i] = `${city[i].toUpperCase()}${city[ @@ -171,9 +172,12 @@ export const genTest = (apiType, dbType) => { Math.min(cityId[i], countryId[i]) + Math.max(cityId[i], countryId[i]); + RESULT_MATH_2[i] = + 1.23 + Math.min(2.34, 3.45) + Math.max(2.34, 3.45); + // LOG, EXP, POWER, SQRT // only integer verification being computed, hence trunc - RESULT_MATH_2[i] = Math.trunc( + RESULT_MATH_3[i] = Math.trunc( Math.log(cityId[i]) + Math.exp(cityId[i]) + Math.pow(cityId[i], 3) + @@ -227,23 +231,32 @@ export const genTest = (apiType, dbType) => { rowValidation("NC_MATH_1", RESULT_MATH_1); }); + it("Formula: ROUND with decimals, MIN, MAX", () => { + editColumnByName( + "NC_MATH_1", + "NC_MATH_2", + `ROUND(1.2345, 2) + MIN(2.34, 3.45) + MAX(2.34, 3.45)` + ); + rowValidation("NC_MATH_2", RESULT_MATH_2) + }) + it("Formula: LOG, EXP, POWER, SQRT", () => { // if (!isXcdb()) { if (dbType === "mysql") { // SQLITE doesnt support LOG, EXP, POWER SQRT construct editColumnByName( - "NC_MATH_1", "NC_MATH_2", + "NC_MATH_3", `LOG({CityId}) + EXP({CityId}) + POWER({CityId}, 3) + SQRT({CountryId})` ); - rowValidation("NC_MATH_2", RESULT_MATH_2); + rowValidation("NC_MATH_3", RESULT_MATH_3); } }); it("Formula: NOW, EDIT & Delete column", () => { // if (!isXcdb()) editColumnByName("NC_MATH_2", "NC_NOW", `NOW()`); - if (dbType === "mysql") editColumnByName("NC_MATH_2", "NC_NOW", `NOW()`); - else editColumnByName("NC_MATH_1", "NC_NOW", `NOW()`); + if (dbType === "mysql") editColumnByName("NC_MATH_3", "NC_NOW", `NOW()`); + else editColumnByName("NC_MATH_2", "NC_NOW", `NOW()`); deleteColumnByName("NC_NOW"); cy.closeTableTab("City"); From f21c564b4d3ad27ebfa18f01825a5758c94a6bd4 Mon Sep 17 00:00:00 2001 From: Wonkeun No Date: Mon, 24 Oct 2022 00:53:28 -0400 Subject: [PATCH 3/4] feat(formulaUtils):allow decimal for round This commit improves ROUND func description for the user and updates documentation --- packages/nc-gui/utils/formulaUtils.ts | 4 ++-- packages/noco-docs/content/en/setup-and-usages/formulas.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/utils/formulaUtils.ts b/packages/nc-gui/utils/formulaUtils.ts index ca35cac3ac..db8f7148d3 100644 --- a/packages/nc-gui/utils/formulaUtils.ts +++ b/packages/nc-gui/utils/formulaUtils.ts @@ -181,8 +181,8 @@ const formulas: Record = { }, }, description: 'Rounded number to a specified number of decimal places or the nearest integer if not specified', - syntax: 'ROUND(value, length), ROUND(value)', - examples: ['ROUND(3.1415,2) => 3.14', 'ROUND(3.1415) => 3', 'ROUND({column1}, 3)'], + syntax: 'ROUND(value, precision), ROUND(value)', + examples: ['ROUND(3.1415) => 3', 'ROUND(3.1415,2) => 3.14', 'ROUND({column1}, 3)'], }, MOD: { type: formulaTypes.NUMERIC, diff --git a/packages/noco-docs/content/en/setup-and-usages/formulas.md b/packages/noco-docs/content/en/setup-and-usages/formulas.md index 9d6a351bba..6d39cb250d 100644 --- a/packages/noco-docs/content/en/setup-and-usages/formulas.md +++ b/packages/noco-docs/content/en/setup-and-usages/formulas.md @@ -49,7 +49,7 @@ Unlike other column types, formula cells cannot be modified by double-clicking s | **MIN** | `MIN(value1,[value2,...])` | `MIN({Column1}, {Column2}, {Column3})` | Minimum value amongst input parameters | | **MOD** | `MOD(value1, value2)` | `MOD({Column}, 2)` | Remainder after integer division of input parameters | | **POWER** | `POWER(base, exponent)` | `POWER({Column}, 3)` | `base` to the `exponent` power, as in `base ^ exponent` | -| **ROUND** | `ROUND(value)` | `ROUND({Column})` | Nearest integer to the input parameter | +| **ROUND** | `ROUND(value, precision)` | `ROUND({Column}, 3)` | Round input `value` to decimal place specified by `precision` (Nearest integer if `precision` not provided) | | **SQRT** | `SQRT(value)` | `SQRT({Column})` | Square root of the input parameter | From cc3ca2c71a26e0ffe124e5a0062a414345693c01 Mon Sep 17 00:00:00 2001 From: Wonkeun No Date: Mon, 24 Oct 2022 01:24:02 -0400 Subject: [PATCH 4/4] feat(formulaUtils):allow decimal for round Add a proper spacing in function description --- packages/nc-gui/utils/formulaUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nc-gui/utils/formulaUtils.ts b/packages/nc-gui/utils/formulaUtils.ts index db8f7148d3..e49655338f 100644 --- a/packages/nc-gui/utils/formulaUtils.ts +++ b/packages/nc-gui/utils/formulaUtils.ts @@ -182,7 +182,7 @@ const formulas: Record = { }, description: 'Rounded number to a specified number of decimal places or the nearest integer if not specified', syntax: 'ROUND(value, precision), ROUND(value)', - examples: ['ROUND(3.1415) => 3', 'ROUND(3.1415,2) => 3.14', 'ROUND({column1}, 3)'], + examples: ['ROUND(3.1415) => 3', 'ROUND(3.1415, 2) => 3.14', 'ROUND({column1}, 3)'], }, MOD: { type: formulaTypes.NUMERIC,