Javascript
금액 문자열에 ,(컴마) 로 자릿수 구분하기
쫑가르카스
2015. 10. 20. 18:25
금액 문자열에 ,(컴마) 로 자릿수 구분하기
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;
}