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

· 9년 전 · 362

 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년 전 조회 497
9년 전 조회 501
9년 전 조회 883
9년 전 조회 265
9년 전 조회 479
9년 전 조회 602
9년 전 조회 613
9년 전 조회 567
9년 전 조회 537
9년 전 조회 692
9년 전 조회 424
9년 전 조회 487
9년 전 조회 363
9년 전 조회 329
9년 전 조회 338
9년 전 조회 325
9년 전 조회 323
9년 전 조회 288
9년 전 조회 289
9년 전 조회 779
9년 전 조회 295
9년 전 조회 260
9년 전 조회 268
9년 전 조회 243
9년 전 조회 284
🐛 버그신고