BLOG ARTICLE 쉼표넣기 | 1 ARTICLE FOUND

  1. 2011.07.27 [javascript] 화폐단위 숫자 세자리마다 쉼표넣기 (2)


function commaNum(num) { 
    if (num < 0) { num *= -1; var minus = true}
    else var minus = false     
    var dotPos = (num+"").split(".")
    var dotU = dotPos[0]
    var dotD = dotPos[1]
    var commaFlag = dotU.length%3

    if(commaFlag) {
            var out = dotU.substring(0, commaFlag) 
            if (dotU.length > 3) out += ","
    }
    else var out = ""
    for (var i=commaFlag; i < dotU.length; i+=3) {
            out += dotU.substring(i, i+3) 
            if( i < dotU.length-3) out += ","
    }
    if(minus) out = "-" + out
    if(dotD) return out + "." + dotD
    else return out
}

YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST
  1. Топики 2014.02.11 18:17  댓글주소  수정/삭제  댓글쓰기

    정보를 주셔서 감사합니다