MCPcopy Index your code
hub / github.com/WardAnalytics/WardGraph / formatNumber

Function formatNumber

src/utils/formatNumber.tsx:14–27  ·  view source on GitHub ↗
(num: number)

Source from the content-addressed store, hash-verified

12 Example: 1000000000000000000000000000000 -> $1000000000000000000
13*/
14export default function formatNumber(num: number): string {
15 if (num < 0) return "Unknown"; // If the number is negative, return "unknown
16
17 // Always round the number to two decimal places
18 num = Math.round(num * 100) / 100;
19
20 if (num >= 1e3 && num < 1e6) return "$" + (num / 1e3).toFixed(1) + "k"; // thousands
21 if (num >= 1e6 && num < 1e9) return "$" + (num / 1e6).toFixed(1) + " Million"; // millions
22 if (num >= 1e9 && num < 1e12)
23 return "$" + (num / 1e9).toFixed(1) + " Billion"; // billions
24 if (num >= 1e12) return "$" + (num / 1e12).toFixed(1) + " Trillion"; // trillions
25
26 return "$" + num.toString();
27}

Callers 8

TransactionRowFunction · 0.85
TransactionTooltipFunction · 0.85
TransactionRowFunction · 0.85
AddressRowFunction · 0.85
EntityRowFunction · 0.85
CategoryRowFunction · 0.85
ExposureColumnHeaderFunction · 0.85
EntityRowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected