'toLocaleString not working on numbers less than 10000 in all browsers
I'm working on an application, that displays numbers according to the user's configuration. Everything works as expected, except when I try with numbers less than 10000,in Chrome, with the following locale: "es-AR". Any ideas?
Chrome:
Firefox:
console.log( (10000).toLocaleString("es-AR") );
console.log( (9999).toLocaleString("es-AR") );
console.log( (9999).toLocaleString("en-US") );
Solution 1:[1]
Minimum Grouping Digits for Spain's Spanish language, according CLDR, is indeed two.
Full language specifications can be found in GitHub.
Interestingly enough, using always a minimum of two grouping digits is in conflict with the RAE rules. They state that this recommendation doesn't apply to all contexts, mentioning as specific exceptions accountancy and any context where it can involve a security risk.
Solution 2:[2]
Given that the spec forces this behavior and that real-life experience is that this is sometimes reported as a bug that needs fixing, here is a simple workaround as requested by the original poster. It's as dirty as detecting four integer digits and adding the thousands separator manually (and could be done many better ways).
var decimals=2;
value=value.toLocaleString('es', {minimumFractionDigits: decimals, maximumFractionDigits: decimals});
//fix spanish thousands separator for <10.000
if(value.indexOf(',')==4 || (decimals==0 && value.length==4)){
value=value.substr(0,1)+'.'+value.substr(1);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JesusIniesta |
| Solution 2 | guidod |



