math

Functions

compareNumbers(a, b, operator)boolean

Check if a is comparative to b with the given operator.

evaluate(equation)number

Evaluate mathematical strings.

isNumeric(val)boolean

Check if the given value is a valid finite number.

isSafeNumber(val)boolean

Check if the given value is a "safe" number.

A "safe" number falls within the Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER values (Inclusive).

sumArray(numbers)number

Take an array of numbers and add the values together.

toFixed(num, [precision])number

Round a number to the given amount of digits after the decimal point, removing any trailing zeros after the decimal point.

compareNumbers(a, b, operator) ⇒ boolean

Check if a is comparative to b with the given operator.

Kind: global function
Returns: boolean - true if the comparison matches, false otherwise

ParamTypeDescription
anumberThe number to compare with b
bnumberThe number to compare with a
operatorstringA valid comparative operator: =, <, >, <=, >=, !=, <>

Example (Is `a` greater than `b`?)

const a = 4;
const b = 2;

compareNumber(a, b, '>'); // true

Example (Is `a` equal to `b`?)

const a = 4;
const b = 2;

compareNumber(a, b, '='); // false

evaluate(equation) ⇒ number

Evaluate mathematical strings.

Kind: global function
Returns: number - The result of the equation

ParamTypeDescription
equationstringThe mathematical equation to compute.

Example

evaluate('5+6'); // 11

isNumeric(val) ⇒ boolean

Check if the given value is a valid finite number.

Kind: global function
Returns: boolean - true if it is a finite number, false otherwise

ParamType
val*

isSafeNumber(val) ⇒ boolean

Check if the given value is a "safe" number.

A "safe" number falls within the Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER values (Inclusive).

Kind: global function
Returns: boolean - true if the value is a "safe" number, false otherwise

ParamType
val*

sumArray(numbers) ⇒ number

Take an array of numbers and add the values together.

Kind: global function
Returns: number - The summed value

ParamType
numbersArray.<number>

toFixed(num, [precision]) ⇒ number

Round a number to the given amount of digits after the decimal point, removing any trailing zeros after the decimal point.

Kind: global function

ParamTypeDefaultDescription
numnumberThe number to round
[precision]number0The number of digits after the decimal point

Example

toFixed(1.236, 2); // 1.24
toFixed(30.1, 2); // 30.1
toFixed(4.0000000004, 3); // 4