数字格式化工具类修改

This commit is contained in:
xiaozzzi 2023-12-03 01:10:48 +08:00
parent 6638563cac
commit 957cd6bc6b

View File

@ -233,11 +233,15 @@ export const formatFileSize = (size: number): string => {
/** /**
* *
* @param param * @param param
* @returns * @returns
*/ */
export const formartNumber = (param: number): string => { export const formartNumber = (param: number): string => {
let num: string = (param || 0).toString(), let num: string = (param || 0).toString()
result: string = '' let result: string = ''
let isNegative = param < 0
if (isNegative) {
num = num.substring(1)
}
while (num.length > 3) { while (num.length > 3) {
result = ',' + num.slice(-3) + result result = ',' + num.slice(-3) + result
num = num.slice(0, num.length - 3) num = num.slice(0, num.length - 3)
@ -245,6 +249,9 @@ export const formartNumber = (param: number): string => {
if (num) { if (num) {
result = num + result result = num + result
} }
if (isNegative) {
return '-' + result
}
return result return result
} }