File size: 503 Bytes
139ef57
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
export function formatLargeNumber(num: number): string {
  if (num < 1000) {
    return num.toString(); // Display as-is for numbers under 1000
  } else if (num < 1000000) {
    // Format for thousands
    return (num / 1000).toFixed(num < 10000 ? 1 : 0) + "K";
  } else if (num < 1000000000) {
    // Format for millions
    return (num / 1000000).toFixed(num < 10000000 ? 1 : 0) + "M";
  } else {
    // Format for billions
    return (num / 1000000000).toFixed(num < 10000000000 ? 1 : 0) + "B";
  }
}