javascript로 number_format 구현

-- JavaScript 2013. 9. 26. 15:58
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Number.prototype.number_format = function(round_decimal) {


    return this.toFixed(round_decimal).replace(/(\d)(?=(\d{3})+$)/g, "$1,");
};



var num = 1003;
alert( num.number_format(0) ); // 1,003

var num2 = 1004.1234;
alert( num2.number_format(2) ); // 1,004.12

posted by 어린왕자악꿍