MCPcopy Create free account
hub / github.com/arctic-cli/interface / formatCompactNumber

Function formatCompactNumber

packages/arctic/src/session/usage-format.ts:228–244  ·  view source on GitHub ↗
(value: number)

Source from the content-addressed store, hash-verified

226}
227
228function formatCompactNumber(value: number): string {
229 const abs = Math.abs(value)
230 const units = [
231 { value: 1_000_000_000_000, suffix: "T" },
232 { value: 1_000_000_000, suffix: "B" },
233 { value: 1_000_000, suffix: "M" },
234 { value: 1_000, suffix: "k" },
235 ]
236 for (const unit of units) {
237 if (abs >= unit.value) {
238 const scaled = value / unit.value
239 const precision = Math.abs(scaled) < 10 ? 1 : 0
240 return `${scaled.toFixed(precision).replace(/\.0$/, "")}${unit.suffix}`
241 }
242 }
243 return Math.round(value) === value ? value.toString() : value.toFixed(1).replace(/\.0$/, "")
244}

Callers 1

formatTokenUsageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected