Caplin Trader 4.5.2

Class: module:br/util/Number

module:br/util/Number

Utility methods for numbers

Constructor

new module:br/util/Number()

Methods

(static) decimalPlaces(n) → {Number}

Counts the amount of decimal places within a number. Also supports scientific notations
Parameters:
Name Type Description
n Number The number (or a number as a string).
Returns:
The number of decimal places
Type
Number

(static) isNumber(n) → {boolean}

Parameters:
Name Type Description
n Object
Returns:
true for numbers and their string representations and false for other values including non-numeric strings, null, Infinity, NaN.
Type
boolean

(static) log10(n) → {Number}

Logarithm to base 10.
Parameters:
Name Type Description
n Number The number (or a number as a string).
Returns:
The logarithm to base 10.
Type
Number

(static) pad(value, numLength) → {String}

Pads the integer part of a number with zeros to reach the specified length.
Parameters:
Name Type Description
value Number The number (or a number as a string).
numLength Number The required length of the number.
Returns:
The formatted number.
Type
String

(static) round(n) → {Number}

Rounds a floating point number
Parameters:
Name Type Description
n Number The number (or a number as a string).
Returns:
The formatted number.
Type
Number

(static) sgn(n) → {int}

Returns a numeric representation of the sign on the number.
Parameters:
Name Type Description
n Number The number (or a number as a string)
Returns:
1 for positive values, -1 for negative values, or the original value for zero and non-numeric values.
Type
int

(static) toFixed(n, dp) → {String}

Formats the number to the specified number of decimal places.
Parameters:
Name Type Description
n Number The number (or a number as a string).
dp Number The number of decimal places.
Returns:
The formatted number.
Type
String

(static) toPrecision(n, sf) → {String}

Formats the number to the specified number of significant figures. This fixes the bugs in the native Number function of the same name that are prevalent in various browsers. If the number of significant figures is less than one, then the function has no effect.
Parameters:
Name Type Description
n Number The number (or a number as a string).
sf Number The number of significant figures.
Returns:
The formatted number.
Type
String

(static) toRounded(n, rounding) → {String}

Formats the number to the specified number of decimal places, omitting any trailing zeros.
Parameters:
Name Type Description
n Number The number (or a number as a string).
rounding Number The number of decimal places to round.
Returns:
The rounded number.
Type
String