From 64b665e706560c0f35325b4195891e76d7ae6041 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 7 Feb 2019 11:18:32 +0000 Subject: [PATCH] More maths operators --- core/modules/filters/math.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/core/modules/filters/math.js b/core/modules/filters/math.js index e28e7fe77..d07192d91 100644 --- a/core/modules/filters/math.js +++ b/core/modules/filters/math.js @@ -75,6 +75,18 @@ exports.min = makeNumericBinaryOperator( function(a,b) {return Math.min(a,b);} ); +exports.fixed = makeNumericBinaryOperator( + function(a,b) {return Number.prototype.toFixed.call(a,b);} +); + +exports.precision = makeNumericBinaryOperator( + function(a,b) {return Number.prototype.toPrecision.call(a,b);} +); + +exports.exponential = makeNumericBinaryOperator( + function(a,b) {return Number.prototype.toExponential.call(a,b);} +); + exports.sum = makeNumericArrayOperator( function(accumulator,value) {return accumulator + value}, 0 // Initial value @@ -104,7 +116,7 @@ function makeNumericBinaryOperator(fnCalc) { }); return result; }; -}; +} function makeNumericArrayOperator(fnCalc,initialValue) { initialValue = initialValue || 0; @@ -117,7 +129,7 @@ function makeNumericArrayOperator(fnCalc,initialValue) { return fnCalc(accumulator,parseNumber(currentValue)); },initialValue))]; }; -}; +} function parseNumber(str) { return parseFloat(str) || 0;