금액 문자열에 ,(컴마) 로 자릿수 구분하기

Javascript 2015. 10. 20. 18:25
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

금액 문자열에  ,(컴마) 로 자릿수 구분하기


function comma(obj){


  //3자리 단위로 콤마 찍기

      var newValue = obj + ""; //숫자인 경우 문자열로 변환

      var len = newValue.length;

      var ch = "";

      var j = 1;

      var formatValue = "";


     // 콤마 ( , ) 제거하기

      newValue = delChar(newValue, ',');

     //comma 제거된 문자열 길이

      len = newValue.length;

 

      for (i = len; i > 0; i--)

      {

            ch = newValue.substring(i - 1, i);

            formatValue = ch + formatValue;


            if ((j % 3) == 0 && i > 1)

            {

                  formatValue = "," + formatValue;

            }

  

            j++;

       }

 

    return formatValue;

 }