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

· 10년 전 · 380

 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에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
9년 전 조회 519
9년 전 조회 517
9년 전 조회 906
9년 전 조회 285
9년 전 조회 491
9년 전 조회 622
9년 전 조회 630
10년 전 조회 588
10년 전 조회 555
10년 전 조회 713
10년 전 조회 443
10년 전 조회 506
10년 전 조회 381
10년 전 조회 346
10년 전 조회 355
10년 전 조회 341
10년 전 조회 345
10년 전 조회 301
10년 전 조회 309
10년 전 조회 804
10년 전 조회 309
10년 전 조회 272
10년 전 조회 284
10년 전 조회 253
10년 전 조회 300