/**
* 数字格式化
* 10000 => "10,000"
* @param num 需要格式化的数字
*/
function toThousandFilter(num) {
return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','));
}
//用法:
toThousandFilter(12345678); // 12,345,678
/**
* 数字格式化
* 10000 => "10,000"
* @param num 需要格式化的数字
*/
function toThousandFilter(num) {
return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','));
}
//用法:
toThousandFilter(12345678); // 12,345,678
本文标题:数字格式化10000 => 10,000
本文链接:https://www.haomeiwen.com/subject/cgtvchtx.html
网友评论