数字格式化工具类修改

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