티스토리 뷰

개발-코딩/script

세자리수 콤마

Hello™ 2013. 10. 2. 09:00

//합계 계산하기
frmView.selectAmount.value=TotFee.setComma();
frmView.shipFee.value=shipFee.setComma();
frmView.lectureDiscount.value=lectureDiscountAmount.setComma();

 

document.getElementById('selItemPrice').innerHTML=(TotFee+shipFee-lectureDiscountAmount).setComma();

이런식으로 처리했음.

그렇다면 setComman(); 를 알아봐야지.

 

//-----------------------------------------------------------------------------
// 3자리마다 콤마찍기(문자변수일때)
// @return : String
//-----------------------------------------------------------------------------
String.prototype.setComma=function(){
 return this.replace(/(\d)(?=(?:\d{3})+(?!\d))/g,'$1,');
}

//-----------------------------------------------------------------------------
// 3자리마다 콤마찍기(숫자값일때_)
// @return : String
//-----------------------------------------------------------------------------
Number.prototype.setComma=function(){
 return this.toString().replace(/(\d)(?=(?:\d{3})+(?!\d))/g,'$1,');
}

이렇게 처리되었음