From e9a4676f5cc4c6f036988f682de23cef3242be5f Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Sun, 7 Feb 2021 11:29:44 -0800 Subject: [PATCH] New function ROUND() in expressions --- lib/common/expression.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/common/expression.ts b/lib/common/expression.ts index 41f1b23..0a4bfc5 100644 --- a/lib/common/expression.ts +++ b/lib/common/expression.ts @@ -130,6 +130,15 @@ export function evaluateCallback(exp: Expression): Expression { } else if (exp[1] === "LOWER") { if (exp[2] == null) return null; if (!isArray(exp[2])) return toString(exp[2]).toLowerCase(); + } else if (exp[1] === "ROUND") { + const n = exp[2]; + const p = exp.length > 3 ? exp[3] : 0; + if (n == null || p == null) return null; + if (!isArray(n) && !isArray(p)) { + const d = 10 ** p; + const m = n * d * (1 + Number.EPSILON); + return Math.round(m) / d; + } } } else if (exp[0] === "PARAM") { if (exp[1] == null) return null;