JS converts Numbers to three comma separated style of sample code
- 2020-03-30 01:48:53
- OfStack
function formatNum(num)
{
if(!/^(+|-)?(d+)(.d+)?$/.test(num)){alert("wrong!"); return num;}
var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3;
var re = new RegExp().compile("(\d)(\d{3})(,|$)");
while(re.test(b)) b = b.replace(re, "$1,$2$3");
return a +""+ b +""+ c;
}