MCPcopy Create free account
hub / github.com/Rfym21/Qwen2API / formatCompact

Function formatCompact

public/src/utils/format.js:5–16  ·  view source on GitHub ↗
(n, units = {})

Source from the content-addressed store, hash-verified

3// explicitly so this remains pure and testable. Callers supply
4// t('dash.acct.unitK') / t('dash.acct.unitM').
5export function formatCompact(n, units = {}) {
6 const { unitK = 'k', unitM = 'M' } = units
7 const num = Number(n) || 0
8 if (num < 1000) return String(num)
9 if (num < 1_000_000) {
10 const k = num / 1000
11 const formatted = k >= 100 ? Math.round(k) : (Math.round(k * 10) / 10)
12 return `${formatted}${unitK}`
13 }
14 const m = num / 1_000_000
15 return `${Math.round(m * 10) / 10}${unitM}`
16}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected