자바스크립트에서 숫자를 표기할때 3자리마다 콤마를 찍어줘야 할 때가 있다 자주 사용하는 기능인데 매번 만들기란 여간 귀찮은게 아니다.
자바스크립트로 돈계산할때 콤마 … 찍어주자 ㅋㅋ 돈계산을 즐거우니깐
//콤마찍기
function comma(str) {
str = String(str);
return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, '$1,');
}
//콤마풀기
function uncomma(str) {
str = String(str);
return str.replace(/[^\d]+/g, '');
}
//input box에서 사용자 입력시 바로 콤마를 찍어주기 위한 함수도 추가 한다.
function inputNumberFormat(obj) {
obj.value = comma(uncomma(obj.value));
}