Class: NumUtils

NumUtils

new NumUtils()

Util methods about number.
Source:

Methods

(static) getPrimes(max) → {Array}

Returns a primes array from 2 to max number.
Parameters:
Name Type Description
max Int
Source:
Returns:
Type
Array

(static) isFloatEqual(f1, f2, threshold) → {Bool}

Check if f1 and f2 are equal. Since float can not be stored exactly in computer, when abs(f1-f2) <= threshold, this function will returns true.
Parameters:
Name Type Description
f1 Float
f2 Float
threshold Float If not set, a default value will be used.
Source:
Returns:
Type
Bool

(static) isInteger(num) → {Bool}

Check if a number is integer.
Parameters:
Name Type Description
num Number
Source:
Returns:
Type
Bool

(static) toDecimals(num, decimalsLength) → {String}

Output a string with decimalsLength. Not the same to Number.toFixed, this method will not pad with zero. For example, call toDecimals(5.3456, 2) will return '5.35', but call toDecimals(5.1, 2) will simply return '5.1',
Parameters:
Name Type Description
num Number
decimalsLength Int
Source:
Returns:
Type
String