Js数字转千位数的方法

如下所示:

regexNum (num) {

var re =/(-?\d+)(\d{3})/

if(/^.*\..*$/.test(num)){

        var pointIndex =num.lastIndexOf(".")

        var intPart = num.substring(0, pointIndex)

        var pointPart =num.substring(pointIndex+1, num.length)

        intPart = intPart +"";

        while(re.test(intPart)){

            intPart =intPart.replace(re,"$1,$2")

        }

        num = intPart+"."+pointPart

    }else{

        num = num +"";

        while(re.test(num)){

            num =num.replace(re,"$1,$2")

        }

    }

    return num

}

你可能感兴趣的:(Js数字转千位数的方法)