I have tried the accepted answer and agree with that. So I upvoted as well. I may have another workaround without specifying any local, but instead look for the separator manually.
P.s. The digit argument is used to specify the amount of decimal places.
parseLocaleNumber(stringnum: string, digit: number): number {
let retValue: number = parseFloat(stringnum);
var arr: string[] = stringnum.split('');
arr.slice().reverse().forEach((x, i, arr) => {
if (i === digit) {
if (x === '.') {
retValue = parseFloat(stringnum.split(',').join(''));
arr.length = i + 1;
} else if (x === ',') {
retValue = parseFloat(stringnum.split('.').join(''));
arr.length = i + 1;
}
}
});
return retValue;
}
Example to use this method:
console.log(parseLocaleNumber('123,456,789.12'));
// 123456789.12
The code is written with the use of TypeScript.