Tell the user to enter values without thousands separator or remove it before trying to convert numeric strings to numbers.
Another problem is that
parseFloat()
accepts only numeric strings with the period as decimal point. So it might be necessary to replace other decimal points like the comma.
Because both problems are related, supporting input strings with thousands separators is quite difficult.
The simple solution (input must be without thousands separator)
priceEN = price.replace(/[,\u2396\u066B]/g, '.');
priceValue = parseFloat(priceEN);
This will replace other decimal points with the period.
The advanced solution (requires defining or determining a locale)
Get the thousands separator from the locale and remove it from the string. Example for the period (locales using comma as decimal point):
priceLoc = price.replace(/[^0-9-,]/g, ''));
For locales using period as decimal point
priceLoc = price.replace(/[^0-9-.]/g, ''));
The above will also remove other characters like currency symbols. If the decimal point is not the period, pass the resulting string to the regex from the simple example before calling
parseFloat()
.