convert string with dot or comma as decimal separator to number in javascript code example
Example: convert string with dot or comma as decimal separator to number in javascript
function realParseFloat(s)
{
s = s.replace(/[^\d,.-]/g, '');
if (navigator.language.substring(0, 2) !== "de" && /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(s))
{
s = s.replace(/,/g, '');
return parseFloat(s);
}
else if (/^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(s))
{
s = s.replace(/\./g, '');
s = s.replace(/,/g, '.');
return parseFloat(s);
}
else
{
s = s.replace(/,/g, '');
return parseFloat(s);
}
}