반응형

 

javascript 숫자 세자리 콤마 제거하기 comma

const numberStr = "123,456,789";

// 전체 콤마 제거
const number = numberStr.replace(/,/g, "");
document.write(number);

 

ASP 숫자형 리턴 - 숫자인지 문자인지 알수 없어서 formatnumber를 적용 못할때 해당 function으로 적용해본다. 

 
 Function My_IsNumeric(value)
    My_IsNumeric = False
    If IsNull(value) Then Exit Function
    My_IsNumeric = IsNumeric(CStr(value))
End Function



        if( len(view_val_acc) > 0 and My_IsNumeric(view_val_acc) = True )then 
            view_val_acc = formatNumber(view_val_acc,0)
        end if 
        'response.write "*"& view_val_acc

 

반응형
반응형

[Javascript] 숫자 3자리 단위마다 콤마(comma) 찍기 

stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript

 

How to print a number with commas as thousands separators in JavaScript

I am trying to print an integer in JavaScript with commas as thousands separators. For example, I want to show the number 1234567 as "1,234,567". How would I go about doing this? Here is how I am...

stackoverflow.com

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
 
function comma(num){
    var len, point, str; 
       
    num = num + ""; 
    point = num.length % 3 ;
    len = num.length; 
   
    str = num.substring(0, point); 
    while (point < len) { 
        if (str != "") str += ","; 
        str += num.substring(point, point + 3); 
        point += 3; 
    } 
     
    return str;
 
}

 

 

반응형

+ Recent posts