New function ROUND() in expressions

This commit is contained in:
Zaid Abdulla committed 2021-02-07 11:29:44 -08:00
1 parent 12197f3b2a
commit e9a4676f5c
1 file changed
+9
+9
View File
@@ -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;