From b7ffe92a4028075bac1d34c11a2b1e2b5a6032e8 Mon Sep 17 00:00:00 2001 From: Adi Fatkhurozi Date: Mon, 10 Jul 2023 09:15:17 +0700 Subject: [PATCH] fix: update function of number --- package-lock.json | 14 +++++++------- package.json | 2 +- src/v2/parser/example.ts | 10 ++++++++++ src/v2/parser/formula-operator-prefix.ts | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11d3867..5b6c953 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.3.3-development", "license": "MIT", "dependencies": { - "@adifkz/exp-p": "^1.0.15", + "@adifkz/exp-p": "^1.0.16", "@babel/runtime": "^7.21.0", "eslint-plugin-jest": "^27.2.1", "expressionparser": "^1.1.5", @@ -54,9 +54,9 @@ } }, "node_modules/@adifkz/exp-p": { - "version": "1.0.15", - "resolved": "https://registry.npmjs.org/@adifkz/exp-p/-/exp-p-1.0.15.tgz", - "integrity": "sha512-SlkHIsTIxBdQ3M+jXva9N6swR8HVqS7I8tgkzisQUBuudGbktLCfxxt3+MnjfsVWSqREGcHOeNuTyQEmtC7OKQ==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/@adifkz/exp-p/-/exp-p-1.0.16.tgz", + "integrity": "sha512-Up+vJPgOj396rtUiVlK11jbhAZuyq0uC/BcyrOD8LunVVELtLXvI+BO6fAspavotJX9eit3d6F7lQ1OMYYQNSQ==", "dependencies": { "luxon": "^3.3.0" } @@ -26283,9 +26283,9 @@ }, "dependencies": { "@adifkz/exp-p": { - "version": "1.0.15", - "resolved": "https://registry.npmjs.org/@adifkz/exp-p/-/exp-p-1.0.15.tgz", - "integrity": "sha512-SlkHIsTIxBdQ3M+jXva9N6swR8HVqS7I8tgkzisQUBuudGbktLCfxxt3+MnjfsVWSqREGcHOeNuTyQEmtC7OKQ==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/@adifkz/exp-p/-/exp-p-1.0.16.tgz", + "integrity": "sha512-Up+vJPgOj396rtUiVlK11jbhAZuyq0uC/BcyrOD8LunVVELtLXvI+BO6fAspavotJX9eit3d6F7lQ1OMYYQNSQ==", "requires": { "luxon": "^3.3.0" } diff --git a/package.json b/package.json index 61cfcbd..77b452a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "access": "public" }, "dependencies": { - "@adifkz/exp-p": "^1.0.15", + "@adifkz/exp-p": "^1.0.16", "@babel/runtime": "^7.21.0", "eslint-plugin-jest": "^27.2.1", "expressionparser": "^1.1.5", diff --git a/src/v2/parser/example.ts b/src/v2/parser/example.ts index 58c96a8..efe6149 100644 --- a/src/v2/parser/example.ts +++ b/src/v2/parser/example.ts @@ -251,6 +251,16 @@ export const ExamplePrefixNumber = { result: 3, description: "", }, + PRECISION: { + expression: "PRECISION(12.34343434, 4)", + result: 12.34, + description: "", + }, + FIXED: { + expression: "FIXED(12.34343434, 4)", + result: 12.3434, + description: "", + }, ADD: { expression: "ADD(1, 2)", result: 3, diff --git a/src/v2/parser/formula-operator-prefix.ts b/src/v2/parser/formula-operator-prefix.ts index 08f96c3..880f9d9 100644 --- a/src/v2/parser/formula-operator-prefix.ts +++ b/src/v2/parser/formula-operator-prefix.ts @@ -137,6 +137,8 @@ export const createPrefixOperator = () => { SUB: (a, b) => num(a()) - num(b()), MUL: (a, b) => num(a()) * num(b()), DIV: (a, b) => num(a()) / num(b()), + PRECISION: (a, b) => +(num(a()).toPrecision(num(b()))), + FIXED: (a, b) => +(num(a()).toFixed(num(b()))), }; const PREFIX_BOOLEAN: FunctionOps = {