MCPcopy
hub / github.com/formatjs/formatjs / digitCount

Function digitCount

packages/bigdecimal/index.ts:27–44  ·  view source on GitHub ↗
(n: bigint)

Source from the content-addressed store, hash-verified

25}
26
27function digitCount(n: bigint): number {
28 if (n === 0n) return 1
29 if (n < 0n) n = -n
30 let count = 0
31 // Fast path: skip 15 digits at a time
32 const big15 = 1000000000000000n
33 while (n >= big15) {
34 n /= big15
35 count += 15
36 }
37 // Remaining digits
38 let r = Number(n)
39 while (r >= 1) {
40 r /= 10
41 count++
42 }
43 return count
44}
45
46const TEN_BIGINT = 10n
47

Callers 1

_log10Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected