MCPcopy
hub / github.com/CaliCastle/cali.so / prettifyNumber

Function prettifyNumber

lib/math.ts:18–36  ·  view source on GitHub ↗
(n: number, inChinese = false)

Source from the content-addressed store, hash-verified

16}
17
18export function prettifyNumber(n: number, inChinese = false): string {
19 if (inChinese) {
20 if (Math.abs(n) >= 100000000) {
21 return toFixed(n / 100000000) + '亿'
22 } else if (Math.abs(n) >= 10000) {
23 return toFixed(n / 10000) + '万'
24 } else {
25 return Intl.NumberFormat('en-US').format(n)
26 }
27 }
28
29 if (Math.abs(n) >= 1000000) {
30 return toFixed(n / 1000000) + 'm'
31 } else if (Math.abs(n) >= 1000) {
32 return toFixed(n / 1000) + 'k'
33 } else {
34 return Intl.NumberFormat('en-US').format(n)
35 }
36}

Callers 4

TotalPageViewsFunction · 0.90
BlogPostCardFunction · 0.90
BlogPostPageFunction · 0.90
ReactIconFunction · 0.90

Calls 1

toFixedFunction · 0.85

Tested by

no test coverage detected