//num 是傳過來的值,del是要保留幾位it
function valueFmt(num, del) {
if (num != '') {
if (del != 0) {
num = parseFloat(num).toFixed(del);
}
var source = String(num).split(".");
source[0] = source[0].replace(new RegExp('(\\d)(?=(\\d{3})+$)', 'ig'), "$1,");
return source.join(".") == "NaN" ? "0.00" : source.join(".");
}
};iovar num = 2.00;console
var result=valueFmt(num,2);function
console.log(result);//結果是:2.00di