2022-04-06 18:29:04 +00:00
|
|
|
/**
|
|
|
|
* Appends a letter depending on the size of the number
|
|
|
|
* @param number A number or string number
|
|
|
|
* @returns A number string with an appropriate letter appended
|
|
|
|
*/
|
2022-04-23 18:10:12 +00:00
|
|
|
export function formatNumbers(number: string | number): string | number {
|
|
|
|
var numberUnformatted = parseFloat(number as string);
|
2022-04-06 18:29:04 +00:00
|
|
|
if (numberUnformatted > 999999999) {
|
|
|
|
var numberFormatted =
|
|
|
|
(numberUnformatted / 1000000000).toFixed(1).toString() + "B";
|
|
|
|
} else if (numberUnformatted > 999999) {
|
|
|
|
var numberFormatted =
|
|
|
|
(numberUnformatted / 1000000).toFixed(1).toString() + "M";
|
|
|
|
} else if (numberUnformatted > 999) {
|
|
|
|
var numberFormatted =
|
|
|
|
(numberUnformatted / 1000).toFixed(1).toString() + "K";
|
|
|
|
} else {
|
|
|
|
var numberFormatted = numberUnformatted.toString();
|
|
|
|
}
|
|
|
|
return numberFormatted;
|
|
|
|
}
|