I had a problem trying to replace spaces in a number. For example, this works, that is, returns 27721, as expected:
While - I don’t know why - this is not so (my browser is in French, so a thousand separators is a space):
function getThousandSeparator() {
var testN = 1000;
return testN.toLocaleString().replace(/\d/g,"");
}
alert("27 721".replace(new RegExp(getThousandSeparator(), "g"), ""));
Run codeHide resultAnd if I force the function to directly return "", then it works. Also, if you test:
console.log(getThousandSeparator() == " ");
it shows false ... Thank you in advance.
source
share