MCPcopy Create free account
hub / github.com/Open-Dev-Society/OpenStock / formatNumber

Function formatNumber

lib/utils.ts:122–133  ·  view source on GitHub ↗
(num: number)

Source from the content-addressed store, hash-verified

120export const formatCurrency = formatPrice;
121
122export function formatNumber(num: number): string {
123 // If number is small (likely already in millions from Finnhub), multiply by 1M to get actual value
124 // Typical mega-cap is > 100B. 100B in millions is 100,000.
125 // If we assume typical market cap input IS millions:
126 const value = num * 1000000;
127
128 if (value >= 1e12) return (value / 1e12).toFixed(2) + 'T';
129 if (value >= 1e9) return (value / 1e9).toFixed(2) + 'B';
130 if (value >= 1e6) return (value / 1e6).toFixed(2) + 'M';
131 if (value >= 1e3) return (value / 1e3).toFixed(2) + 'K';
132 return value.toString();
133}
134
135export const formatDateToday = new Date().toLocaleDateString('en-US', {
136 weekday: 'long',

Callers 1

WatchlistTableFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected