개발새발

[java script] 화폐단위 콤마 함수 본문

Web Programming/Javascript

[java script] 화폐단위 콤마 함수

재래김유진 2020. 2. 18. 12:32
728x90
반응형

 

1
2
3
4
    function AddComma(num){
        var regexp = /\B(?=(\d{3})+(?!\d))/g;
        return num.toString().replace(regexp, ',');
        }
     
 

 

 

<example>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    function AddComma(num){
        var regexp = /\B(?=(\d{3})+(?!\d))/g;
        return num.toString().replace(regexp, ',');
        }
 
    for(var i = 0; i <obj['data'].length; i++){ 
          
          var priceClose = AddComma(obj.data[i].priceClose);
          var priceAvg5 = AddComma(obj.data[i].priceAvg5);
          var priceAvg10 = AddComma(obj.data[i].priceAvg10);
          var priceAvg20 = AddComma(obj.data[i].priceAvg20);
          var priceAvg60 = AddComma(obj.data[i].priceAvg60);
          var volume = AddComma(obj.data[i].volume);
          var volumeAvg5 = AddComma(obj.data[i].volumeAvg5);
          var volumeAvg20 = AddComma(obj.data[i].volumeAvg20);
          var volumeAvg60 = AddComma(obj.data[i].volumeAvg60);
          
          
          html += '<tr>'; 
          html += '<td class="listtd">'+obj.data[i].dealDate+'</td>'; 
          html += '<td class="listtd">'+priceClose+'</td>'; 
          html += '<td class="listtd">'+priceAvg5+'</td>'; 
          html += '<td class="listtd">'+priceAvg10+'</td>'; 
          html += '<td class="listtd">'+priceAvg20+'</td>'; 
          html += '<td class="listtd">'+priceAvg60+'</td>'; 
          html += '<td class="listtd">'+volume+'</td>'; 
          html += '<td class="listtd">'+volumeAvg5+'</td>'; 
          html += '<td class="listtd">'+volumeAvg20+'</td>'; 
          html += '<td class="listtd">'+volumeAvg60+'</td>'; 
          html += '</tr>'; 
          }
 
 
728x90
반응형
Comments