ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • javaScript) 돈 콤마 찍기 꿀팁
    Programing Language/JavaScript 2021. 6. 3. 16:08
    728x90
    반응형

     

    예시

    const n1 = 12345.6789;
    
    
    const cn1 = n1.toLocaleString('ko-KR');
    
    
    console.log(cn1)  //12,345.679
    

    2. toLocaleString() 함수 이용하기

    toLocaleString() 함수

    toLocaleString() 함수를 사용하여 간단하게 천단위마다 콤마를 추가할 수 있습니다.

    number.toLocaleString(locales, options)

    toLocaleString() 함수는 숫자를 로컬의 language format에 맞는 문자열로 변경해 줍니다.

    파라미터로 아무것도 전달되지 않으면 사용자 로컬 환경의 locale을 default로 사용합니다.

     

     

     파라미터 

    locales

    코드 설명 예시 (1234567)
    ar-SA Arabic (Saudi Arabia) ١٬٢٣٤٬٥٦٧
    bn-BD Bangla (Bangladesh) ১২,৩৪,৫৬৭
    bn-IN Bangla (India) ১২,৩৪,৫৬৭
    cs-CZ Czech (Czech Republic) 1 234 567
    da-DK Danish (Denmark) 1.234.567
    de-AT Austrian German 1 234 567
    de-CH "Swiss" German 1’234’567
    de-DE Standard German (as spoken in Germany) 1.234.567
    el-GR Modern Greek 1.234.567
    en-AU Australian English 1,234,567
    en-CA Canadian English 1,234,567
    en-GB British English 1,234,567
    en-IE Irish English 1,234,567
    en-IN Indian English 12,34,567
    en-NZ New Zealand English 1,234,567
    en-US US English 1,234,567
    en-ZA English (South Africa) 1 234 567
    es-AR Argentine Spanish 1.234.567
    es-CL Chilean Spanish 1.234.567
    es-CO Colombian Spanish 1.234.567
    es-ES Castilian Spanish (as spoken in Central-Northern Spain) 1.234.567
    es-MX Mexican Spanish 1,234,567
    es-US American Spanish 1,234,567
    fi-FI Finnish (Finland) 1 234 567
    fr-BE Belgian French 1 234 567
    fr-CA Canadian French 1 234 567
    fr-CH "Swiss" French 1 234 567
    fr-FR Standard French (especially in France) 1 234 567
    he-IL Hebrew (Israel) 1,234,567
    hi-IN Hindi (India) 12,34,567
    hu-HU Hungarian (Hungary) 1 234 567
    id-ID Indonesian (Indonesia) 1.234.567
    it-CH "Swiss" Italian 1’234’567
    it-IT Standard Italian (as spoken in Italy) 1.234.567
    ja-JP Japanese (Japan) 1,234,567
    ko-KR Korean (Republic of Korea) 1,234,567
    nl-BE Belgian Dutch 1.234.567
    nl-NL Standard Dutch (as spoken in The Netherlands) 1.234.567
    no-NO Norwegian (Norway) 1 234 567
    pl-PL Polish (Poland) 1 234 567
    pt-BR Brazilian Portuguese 1.234.567
    pt-PT European Portuguese (as written and spoken in Portugal) 1 234 567
    ro-RO Romanian (Romania) 1.234.567
    ru-RU Russian (Russian Federation) 1 234 567
    sk-SK Slovak (Slovakia) 1 234 567
    sv-SE Swedish (Sweden) 1 234 567
    ta-IN Indian Tamil 12,34,567
    ta-LK Sri Lankan Tamil 12,34,567
    th-TH Thai (Thailand) 1,234,567
    tr-TR Turkish (Turkey) 1.234.567
    zh-CN Mainland China, simplified characters 1,234,567
    zh-HK Hong Kong, traditional characters 1,234,567
    zh-TW Taiwan, traditional characters 1,234,567

     

    options

    • currency
    • currencyDisplay : "symbol"(default), "code", "name"
    • localeMatcher : "best-fit"(default), "lookup"
    • maximumFractionDigits : 0~20 (default : 3)
    • maximumSignificantDigits : 1~20 (default : 21)
    • minimumFractionDigits : 0~20(default: 3)
    • minimumIntegerDigits : 1~21 (default: 1)
    • minimumSignificantDigits : 1~21 (default : 21)
    • style : "currency", "deciaml" (default), "percent"
    • useGrouping : true(default) /false
    728x90
    반응형
Designed by Tistory.