function formatThousand(num) { num = num + ""; var reg = /(-?d+)(d{3})/; while (reg.test(num)) { var temp = num.replace(reg, "$1,$2"); if (num.indexOf(".") >= 0 && temp.split(".")[1].length > num.split(".")[1].length) { break; } num = temp; } return num; }