blz? How can I convert a currency string (pt-br) value to a float value in javascript.
"10,000,000"
blz? How can I convert a currency string (pt-br) value to a float value in javascript.
"10,000,000"
Steps:
.split('.').join('')
.split(',').join('.')
Number('string');
To do in a row would only be:
Number("10.000,50".split('.').join('').split(',').join('.'));
In function:
function toFloat(str) {
if (typeof str == 'number') return str;
return Number(str.split('.').join('').split(',').join('.'));
}
var testes = ['10.000,50', '105,45', '1.000.005,70'];
console.log(JSON.stringify(testes.map(toFloat))); // [10000.5,105.45,1000005.7]