MCPcopy Index your code
hub / github.com/dataease/SQLBot / formatNumber

Function formatNumber

frontend/src/views/chat/component/charts/utils.ts:9–35  ·  view source on GitHub ↗
(value: any)

Source from the content-addressed store, hash-verified

7 * 支持:正负整数、小数、字符串格式的数值
8 */
9export function formatNumber(value: any): string | number {
10 if (value === null || value === undefined || value === '') {
11 return value
12 }
13
14 let str: string
15 if (typeof value === 'string') {
16 str = value.trim()
17 } else if (typeof value === 'number') {
18 str = String(value)
19 } else {
20 return value
21 }
22
23 const match = str.match(/^([+-])?(\d+)(\.(\d+))?$/)
24 if (!match) {
25 return value
26 }
27
28 const sign = match[1] || ''
29 const intPart = match[2]
30 const decPart = match[3] || ''
31
32 const formattedInt = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
33
34 return sign + formattedInt + decPart
35}
36
37interface CheckedData {
38 isPercent: boolean

Callers 5

initMethod · 0.90
initMethod · 0.90
initMethod · 0.90
initMethod · 0.90
initMethod · 0.90

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected