Constructor
new module:br-util /Number()
Methods
(static) decimal Places(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) is Number(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, num Length) → {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) to Fixed(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) to Precision(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) to Rounded(n, rounding) → {String}
Formats the number to the specified number of decimal places, omitting any trailing zeros.
Parameters:
Name | Type | Description |
---|---|---|
n |
number | string | The number (or a number as a string). |
rounding |
Number | The number of decimal places to round. |
Returns:
The rounded number.
- Type
- String