'콤마'에 해당되는 글 1건

  1. 2008.02.15 숫자에 콤마 붙이기

//============================================================
// 돈 숫자에 ',' 붙이기
//============================================================
function money_point(str){ //함수형
 str = parseInt(str,10);
 str = str.toString().replace(/[^-0-9]/g,'');
 while(str.match(/^(-?\d+)(\d{3})/)) {
        str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2');
    }
 return str;
}
String.prototype.money_point = function(){ //프로토타입형
str=this;
 str = parseInt(str,10);
 str = str.toString().replace(/[^-0-9]/g,'');
 while(str.match(/^(-?\d+)(\d{3})/)) {
        str = str.replace(/^(-?\d+)(\d{3})/, '$1,$2');
    }
 return str;
}


--------------------------------------------------------------------------------


<INPUT style="TEXT-ALIGN: right" onchange="this.value = money_point(this.value);" size=60>

<INPUT style="TEXT-ALIGN: right" onchange="this.value = this.value.toString().money_point();" size=60>

Posted by 알 수 없는 사용자
,