코드 - html 1234567890000000 - script $(window).on('load', function(){ comma(); // 숫자 세자리 콤마 찍기 $('.count').each(function(){ var txt = $(this).text(); $(this).prevAll('.reTxt').remove(); $(this).before('' + txt + ''); }); }); /* 숫자 카운팅 */ function numCount(){ $('.count').each(function(){ var spd = '50';//카운팅 속도 var out = '1000';//카운팅 끝나는 시간 //숫자 자리수 출력 var txt = $(this).text().replace(/,/g, ''); var len = txt.length; $(this).after(''); for(i = 0 ;i < len ; i ++){ $(this).next('.len').append('0'); } var num = $(this).next('.len').text(); var multi = '1' + num; $(this).next('.len').remove(); var $this = $(this); var myCount = setInterval(function(){ //랜덤 숫자 출력 var numRd = Math.random(); $this.text(Math.floor(numRd * multi).toFixed(0)); // .toFixed(0) : 소수점 버리기 comma(); // 숫자 세자리 콤마 찍기 }, spd); setTimeout(function(){ clearInterval(myCount); var reTxt = $this.prev('.reTxt').text(); $this.text(reTxt); }, out); }); } /* 숫자 세자리 콤마 찍기 */ function comma(){ $('.comma').each(function(){ var txt = $(this).text(); $(this).html(txt.replace(/,/g, '')); var len = $(this).text().length; for(i = 0; i < len; i ++){ $(this).eq(i).text(commaNum($(this).eq(i).text())); } }); function commaNum(num){ var len, point, str; num = num + ''; point = num.length % 3 len = num.length; str = num.substring(0, point); while(point < len){ if(str != '') str += ','; str += num.substring(point, point + 3); point += 3; } return str; } }