verce-vue-test 0.0.164 → 0.0.165
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1332 +24 -0
- package/package.json +1 -1
package/1332
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 千分位格式化
|
|
3
|
+
* 非法值统一返回空字符串
|
|
4
|
+
*/
|
|
5
|
+
export const formatThousands = (value: unknown): string => {
|
|
6
|
+
if (value === null || value === undefined || value === '') {
|
|
7
|
+
return ''
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof value !== 'number' && typeof value !== 'string') {
|
|
11
|
+
return ''
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const str = String(value).trim()
|
|
15
|
+
|
|
16
|
+
if (!str || !/^-?\d+(\.\d+)?$/.test(str)) {
|
|
17
|
+
return ''
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [integer, decimal] = str.split('.')
|
|
21
|
+
const formatted = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
22
|
+
|
|
23
|
+
return decimal !== undefined ? `${formatted}.${decimal}` : formatted
|
|
24
|
+
}
|