자바스크립트로 구현한 number_format() 입니다.

· 10년 전 · 417

 function toNumber(str){
  str = str.toString();
  var len = str.length;
  var num = "";
 
  for(i=0; i<len; i++){
   int = parseInt(str.charAt(i));
   if(int >= 0 && int <= 9) num += str.charAt(i);
  }
  return parseInt(num);
 }
 
 function Number_Format(val){
  if(val){
   val = toNumber(val).toString();
   var len = val.length;
      var str = "";
   if(len > 3){
    var in_c = len % 3;
    if(!in_c) in_c = 3;
   
    for(n = 0; n < len; n++){
     if(n == in_c){
      str += ",";
      in_c = 3 + in_c;
     }
     str += val.charAt(n);
       }
    return str;
   }else{
    return val;
   }
  }
 } 

|
댓글을 작성하시려면 로그인이 필요합니다.

팁게시판

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
10년 전 조회 565
10년 전 조회 565
10년 전 조회 951
10년 전 조회 327
10년 전 조회 538
10년 전 조회 663
10년 전 조회 671
10년 전 조회 643
10년 전 조회 603
10년 전 조회 753
10년 전 조회 486
10년 전 조회 549
10년 전 조회 418
10년 전 조회 381
10년 전 조회 393
10년 전 조회 377
10년 전 조회 387
10년 전 조회 337
10년 전 조회 345
10년 전 조회 844
10년 전 조회 340
10년 전 조회 306
10년 전 조회 316
10년 전 조회 287
10년 전 조회 330