Javascript & JQuery & CSS > example - 콤마찍기, 콤마 풀기
등록일 : 2019-09-19 15:20
조회수 : 94,937
str1 = "-123456.789";
str2 = "12,345.789";
alert(comma(str1));
alert(uncomma(str2));
//콤마찍기
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, '');
}
결과1 : -123,456.789
결과 2 : 123456789