MCPcopy
hub / github.com/monkeytypegame/monkeytype / getNumberWithMagnitude

Function getNumberWithMagnitude

frontend/src/ts/utils/numbers.ts:28–62  ·  view source on GitHub ↗
(num: number)

Source from the content-addressed store, hash-verified

26 * and the order of magnitude (e.g., thousand, million, billion).
27 */
28export function getNumberWithMagnitude(num: number): {
29 rounded: number;
30 roundedTo2: number;
31 orderOfMagnitude: string;
32} {
33 const units = [
34 "",
35 "thousand",
36 "million",
37 "billion",
38 "trillion",
39 "quadrillion",
40 "quintillion",
41 "sextillion",
42 "septillion",
43 "octillion",
44 "nonillion",
45 "decillion",
46 ];
47 let unitIndex = 0;
48 let roundedNum = num;
49
50 while (roundedNum >= 1000) {
51 roundedNum /= 1000;
52 unitIndex++;
53 }
54
55 const unit = units[unitIndex] ?? "unknown";
56
57 return {
58 rounded: Math.round(roundedNum),
59 roundedTo2: roundTo2(roundedNum),
60 orderOfMagnitude: unit,
61 };
62}
63
64/**
65 * Abbreviates a large number with a suffix (k, m, b, etc.) representing its order of magnitude.

Callers 2

numberOfHistogramRecordsFunction · 0.90
fetchTypingStatsFunction · 0.90

Calls 1

roundTo2Function · 0.90

Tested by

no test coverage detected