修改数字转换

master
于肖磊 2025-07-18 18:58:28 +08:00
parent f7375d4421
commit 8b41aca299
1 changed files with 3 additions and 2 deletions

View File

@ -918,9 +918,10 @@ export const color_change = (length) => {
* @returns 格式化后的数字字符串
*/
export const formatNumber = (num, is_convert) => {
let new_num = num.replace(/[^0-9.,]/g, '');
if (is_convert) {
// 将输入转换为字符串形式以便处理
const number = num.toString();
const number = new_num.toString();
// 使用正则表达式将整数部分每三位用逗号分隔
const integerPart = number.split('.')[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
// 避免小数为空的时候也处理
@ -929,7 +930,7 @@ export const formatNumber = (num, is_convert) => {
return integerPart + decimalPart;
} else {
// 如果不需要转换,移除所有逗号并返回
return num.toString().replace(/,/g, '');
return new_num.toString().replace(/,/g, '');
}
};