//number_format 以千位分隔符方式格式化一个数字
function number_format(number,decimals,dec_point,thousands_sep) { if(decimals){ number = parseFloat(number).toFixed(decimals); //转化为Float浮点型 并保留指定小数位 } dec_point = dec_point ? dec_point : '.'; thousands_sep = thousands_sep ? thousands_sep : ','; var source = String(number).split("."); source[0] = source[0].replace(new RegExp('(\\d)(?=(\\d{3})+$)','ig'),"$1"+thousands_sep); return source.join(dec_point); } var num = 54623546.547; document.write(number_format(num,2,'.',','));
热门文章