Members
(static, constant) leadingZeroFormat
Formatter - adds leading zeroes to a value (adds max of 8 zeros)
- Source:
Examples
leadingZeroFormat(5, 2)
> '05'
leadingZeroFormat(12, 2)
> '12'
Methods
(static) atMostDecFormat(value) → {String}
Formatter - renders value with at most one decimal point
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Examples
atMostDecFormat(10.89321)
> '10.9'
atMostDecFormat(15)
> '15'
atMostDecFormat(15.001)
> '15.0'
(static) commaFormat(value) → {String}
Formatter - renders values formatted as with thousands separated with commas (or whatever your locale uses as by d3.format(','))
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Example
commaFormat(1396512)
> '1,396,521'
(static) decFormat(numDecimals, value) → {String}
Formatter (curried) - renders to numDecimals
decimal places
Parameters:
Name | Type | Description |
---|---|---|
numDecimals |
Number | number of decimals to use |
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Examples
decFormat(1, 10.89321)
> '10.9'
decFormat(2, 10.89321)
> '10.89'
decFormat(1)(10.89321)
> '10.9'
(static) decPercentFormat(numDecimals, value) → {String}
Formatter (curried) - renders value multiplied by 100
with numDecimal
decimal points.
Commonly used for percentages without the %.
Parameters:
Name | Type | Description |
---|---|---|
numDecimals |
Number | number of decimals to use |
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Example
decPercentFormat(1, 0.8132)
> '81.3'
(static) makePercent(formatter) → {function}
Wraps a formatting function by multiplying the value by 100 and adds a % to the end.
Parameters:
Name | Type | Description |
---|---|---|
formatter |
function | formatter function |
- Source:
Returns:
a formatter function
- Type
- function
(static) makePlusMinus(formatter) → {function}
Wraps a formatting function and puts a + in front of formatted value if it is positive.
Parameters:
Name | Type | Description |
---|---|---|
formatter |
function | formatter function |
- Source:
Returns:
a formatter function
- Type
- function
(static) moneyFormat(value) → {String}
Formatter - renders values formatted as money (prefixed with $, uses commas)
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Example
moneyFormat(9.132)
> '$9.13'
(static) percentFormat(numDecimals, value) → {String}
Formatter (curried) - renders value as a percentage
Parameters:
Name | Type | Description |
---|---|---|
numDecimals |
Number | number of decimals to use |
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Example
percentFormat(1, 0.38523)
> '38.5%'
(static) plusMinusFormat(numDecimals, value) → {String}
Formatter (curried) - renders positive values with a + and negative with a -.
Parameters:
Name | Type | Description |
---|---|---|
numDecimals |
Number | number of decimals to use |
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Examples
plusMinusFormat(1, 0.38523)
> '+0.4'
plusMinusFormat(1, -15)
> '-15.0'
(static) safeFormat(value, formatter)
Returns null/undefined for null/undefined values, otherwise it returns the result of a passed in formatter
Parameters:
Name | Type | Description |
---|---|---|
value |
Any | value to format |
formatter |
function | formatter function |
- Source:
Returns:
Formatted value or null/undefined
(static) seFormat(numDecimals, value) → {String}
Formatter (curried) - renders values prefixed with a ±
Parameters:
Name | Type | Description |
---|---|---|
numDecimals |
Number | number of decimals to use |
value |
Number | value to format |
- Source:
Returns:
formatted value
- Type
- String
Examples
seFormat(1, 0.38523)
> '±0.4'
seFormat(2, -15)
> '±15.00'
(static) zeroAsNull(formatter) → {function}
Wraps a formatter function that replaces the value with null when it is 0. Useful for not rendering zeroes in tables.
Parameters:
Name | Type | Description |
---|---|---|
formatter |
function | formatter function |
- Source:
Returns:
a formatter function
- Type
- function