|
|
@ -14,14 +14,15 @@ export type DecimalUnits = ValueOf<typeof DECIMAL_UNITS>;
|
|
|
|
const TEN_THOUSAND = DECIMAL_UNITS.THOUSAND * 10;
|
|
|
|
const TEN_THOUSAND = DECIMAL_UNITS.THOUSAND * 10;
|
|
|
|
const TEN_MILLIONS = DECIMAL_UNITS.MILLION * 10;
|
|
|
|
const TEN_MILLIONS = DECIMAL_UNITS.MILLION * 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type ShortNumber = [number, DecimalUnits, 0 | 1]; // Array of: shorten number, unit of shorten number and maximum fraction digits
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {number} sourceNumber Number to convert to short number
|
|
|
|
* @param sourceNumber Number to convert to short number
|
|
|
|
* @returns {ShortNumber} Calculated short number
|
|
|
|
* @returns Calculated short number
|
|
|
|
* @example
|
|
|
|
* @example
|
|
|
|
* shortNumber(5936);
|
|
|
|
* shortNumber(5936);
|
|
|
|
* // => [5.936, 1000, 1]
|
|
|
|
* // => [5.936, 1000, 1]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export type ShortNumber = [number, DecimalUnits, 0 | 1]; // Array of: shorten number, unit of shorten number and maximum fraction digits
|
|
|
|
|
|
|
|
export function toShortNumber(sourceNumber: number): ShortNumber {
|
|
|
|
export function toShortNumber(sourceNumber: number): ShortNumber {
|
|
|
|
if (sourceNumber < DECIMAL_UNITS.THOUSAND) {
|
|
|
|
if (sourceNumber < DECIMAL_UNITS.THOUSAND) {
|
|
|
|
return [sourceNumber, DECIMAL_UNITS.ONE, 0];
|
|
|
|
return [sourceNumber, DECIMAL_UNITS.ONE, 0];
|
|
|
@ -45,9 +46,9 @@ export function toShortNumber(sourceNumber: number): ShortNumber {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {number} sourceNumber Original number that is shortened
|
|
|
|
* @param sourceNumber Original number that is shortened
|
|
|
|
* @param {number} division The scale in which short number is displayed
|
|
|
|
* @param division The scale in which short number is displayed
|
|
|
|
* @returns {number} Number that can be used for plurals when short form used
|
|
|
|
* @returns Number that can be used for plurals when short form used
|
|
|
|
* @example
|
|
|
|
* @example
|
|
|
|
* pluralReady(1793, DECIMAL_UNITS.THOUSAND)
|
|
|
|
* pluralReady(1793, DECIMAL_UNITS.THOUSAND)
|
|
|
|
* // => 1790
|
|
|
|
* // => 1790
|
|
|
|