what i have done so far is a multi-step approach that you can see in the code below. nf is a NumberFormat service. This function accepts a formatted number as well as the language used. Now we create a comparator, dividing 10k by 3, thereby guaranteeing the decimal and thousandth separators in a fixed position. Then remove the thousands separator and all other non-numeric characters, such as currency symbols. after that we replace the decimal separator with English and finally return the cast number.
uf(number, locale) { let nf = this.nf({}, locale); let comparer = nf.format(10000 / 3); let thousandSeparator = comparer[1]; let decimalSeparator = comparer[5]; // remove thousand seperator let result = number.replace(thousandSeparator, '') // remove non-numeric signs except -> , . .replace(/[^\d.,-]/g, '') // replace original decimalSeparator with english one .replace(decimalSeparator, '.'); // return real number return Number(result); }
source share