You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
439 B
15 lines
439 B
const formatViewCount = (num: number): string => {
|
|
// Nine Zeroes for Billions
|
|
return Math.abs(num) >= 1.0e9
|
|
? (Math.abs(num) / 1.0e9).toPrecision(3) + "B"
|
|
: // Six Zeroes for Millions
|
|
Math.abs(num) >= 1.0e6
|
|
? (Math.abs(num) / 1.0e6).toPrecision(3) + "M"
|
|
: // Three Zeroes for Thousands
|
|
Math.abs(num) >= 1.0e3
|
|
? (Math.abs(num) / 1.0e3).toPrecision(3) + "K"
|
|
: Math.abs(num).toString();
|
|
};
|
|
|
|
export default formatViewCount;
|