glize/formatters/number

Methods

(static) formatNumber(number, opt_optionsopt, non-null) → {string}

Formats given number according to given options.
Source:
Parameters:
Name Type Attributes Description
number number The number to be formatted.
opt_options Object.<string, *> <optional>
Formatting options.
Returns:
Type:
string
The formatted number string.
Example
formatNumber(100);   // 100
formatNumber(1000);  // 1,000
formatNumber(1500);  // 1,500
formatNumber(10000); // 10,000
formatNumber(1e6);   // 1,000,000
const options = {'prefix': '$'};
formatNumber(100, options);   // $100
formatNumber(1e6, options);   // $1,000,000

(static) ordinal(number) → {string}

Gets the ordinal suffix for a number.
Source:
Parameters:
Name Type Description
number number The number.
Returns:
Type:
string
Returns the ordinal suffix for a number.

(static) roundNumber(number, opt_optionsopt, non-null) → {string}

Rounds given number.
Source:
Parameters:
Name Type Attributes Description
number number The number to be rounded.
opt_options Object.<string, *> <optional>
Formatting options.
Returns:
Type:
string
The rounded number string.
Example
roundNumber(100);   // 100
roundNumber(1000);  // 1k
roundNumber(1500);  // 1.5k
roundNumber(10000); // 10k
roundNumber(1e6);   // 10m
const options = {'prefix': '$'};
roundNumber(100, options);   // $100
roundNumber(1e6, options);   // $10m