js,千分符
function formatNum(num) { num=(num+'').match(/^(?:\s*)(\-?\d+)(\.(\d+))?(?:\s*)$/); if(!num)return ''; var int=num[1].split(''); for(var i=int.length;i>0;i-=3) (i!==int.length)&&int.splice(i,0,','); num[2]&&int.push(num[2]); return int.join(""); }
formatNum(123124.1252564353) //"123,124.1252564353"
formatNum(123124) //"123,124"
formatNum('123225676245342341676435134.23') //"123,225,676,245,342,341,676,435,134.23"
formatNum(-23412412) //"-23,412,412"
本文来自博客园,作者:一夜梦想,转载请注明原文链接:https://www.cnblogs.com/caiyingyong/p/7395621.html