Javascript & JQuery & CSS > example - ÄÞ¸¶Âï±â, ÄÞ¸¶ Ç®±â
µî·ÏÀÏ : 2019-09-19 15:20
Á¶È¸¼ö : 53,664
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