{{ numberToCurrencyNo(1245) }}
export const numberToCurrencyNo = (value: any) => {
if (!value) return 0;
// 获取整数部分
const intPart = Math.trunc(value);
// 整数部分处理,增加,
const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
// 预定义小数部分
let floatPart = "";
// 将数值截取为小数部分和整数部分
const valueArray = value.toString().split(".");
if (valueArray.length === 2) {
// 有小数部分
floatPart = valueArray[1].toString(); // 取得小数部分
return intPartFormat + "." + floatPart;
}
return intPartFormat + floatPart;
};
标签:floatPart,const,intPartFormat,千分,value,toString,vue3,格式化,小数
From: https://www.cnblogs.com/JaneLifeBlog/p/17869208.html