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

· 10년 전 · 414

 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년 전 조회 563
10년 전 조회 562
10년 전 조회 947
10년 전 조회 326
10년 전 조회 538
10년 전 조회 660
10년 전 조회 671
10년 전 조회 642
10년 전 조회 603
10년 전 조회 753
10년 전 조회 483
10년 전 조회 548
10년 전 조회 415
10년 전 조회 380
10년 전 조회 392
10년 전 조회 375
10년 전 조회 386
10년 전 조회 335
10년 전 조회 342
10년 전 조회 838
10년 전 조회 338
10년 전 조회 300
10년 전 조회 311
10년 전 조회 285
10년 전 조회 327