Search code examples
javascriptlocale

Chrome - toLocaleString() - Thousands separator is not working for Spanish


In Chrome, when the locale is set in 'es' the thousands separator is not there.

enter image description here

If I use 4 digit number, there is not problem

Data Set:

(2500).toLocaleString('en')
"2,500"
(2500).toLocaleString('pt')
"2.500"
(2500).toLocaleString('es')
"2500"

(25000).toLocaleString('es')
"25.000"

Why is this happen?


Solution

  • According to the CLDR, this is the intended behavior. The "Minimum Grouping Digits" is 2, meaning that, only when a number has 2 digits before the other 3 digits, the thousand separator would appear. Apparently, this was only applied to chrome, since other browsers are using the "old" specifications.

    Check this https://st.unicode.org/cldr-apps/v#/es/Symbols/70ef5e0c9d323e01

    A possible workaround I used FOR SPECIFIC CASES, is to set it to the German locale ("de") instead of Spanish:

    (1000).toLocaleString("de")

    "1.000"