feat: 实体首页数字过大进行逗号分隔处理

This commit is contained in:
刘洪洪
2023-06-25 10:33:57 +08:00
parent a5690b82e7
commit fcca6142df
2 changed files with 24 additions and 10 deletions

View File

@@ -1283,3 +1283,16 @@ export function toUpperCaseByString (str) {
}
return str
}
/**
* 数字满1000逗号分隔如99999转变为99,999
* 小数点后保留原状,不做逗号分隔,也不进行四舍五入
* @param num
* @returns {string}
*/
export function numberWithCommas (num) {
if (typeof num === 'number') {
return num.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ', ')
} else {
return num
}
}