MCPcopy Create free account
hub / github.com/dataease/SQLBot / formatNumber

Function formatNumber

g2-ssr/charts/utils.js:8–34  ·  view source on GitHub ↗

* 为数值添加千分符,保持原有小数位数不变 * 纯字符串处理,避免精度丢失 * 支持:正负整数、小数、字符串格式的数值

(value)

Source from the content-addressed store, hash-verified

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

Callers 4

getLineOptionsFunction · 0.70
getPieOptionsFunction · 0.70
getBarOptionsFunction · 0.70
getColumnOptionsFunction · 0.70

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected