MCPcopy
hub / github.com/stackshareio/awesome-stacks / shortenLargeNumber

Function shortenLargeNumber

src/utils.js:5–18  ·  view source on GitHub ↗
(num, digits)

Source from the content-addressed store, hash-verified

3}
4
5export function shortenLargeNumber(num, digits) {
6 var units = ['k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'],
7 decimal;
8
9 for (var i = units.length - 1; i >= 0; i--) {
10 decimal = Math.pow(1000, i + 1);
11
12 if (num <= -decimal || num >= decimal) {
13 return +(num / decimal).toFixed(digits) + units[i];
14 }
15 }
16
17 return num;
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected