新建numFormat文件
export default function numFormat(num) {
var c =
num.toString().indexOf(".") !== -1
? num.toLocaleString()
: num.toString().replace(/(\d)(?=(?:\d{3})+$)/g, "$1,");
return c;
}
页面引入及使用
import numFormat from "../../tools/numFormat"
console.log(numFormat(10000))