移动开发|jsjs字符串每三位加逗号,并保留小数点部分

/** * Created by dcp on 2018/9/28. */// 写代码实现一个 cut 函数cut(3123123123.123); //3,123,123,123.123 var num=3123123123.123 function cut(num) { var arr=num.toString().split('.')var t1=arr[0].toString().split(''); var t2=arr[1].toString(); var result=[],counter=0; for(var i=t1.length-1; i>=0; i--){ counter++; result.unshift(t1[i]); if((counter%3)==0&&i!=0) { result.unshift(','); } } var t3=result.join('') var t4=t3+'.'+t2 return t4} console.log(cut(num))

    推荐阅读