0
blz? How can I convert a currency string value (en) to a float value in javascript.
"10,000.50"
0
blz? How can I convert a currency string value (en) to a float value in javascript.
"10,000.50"
1
Footsteps:
.split('.').join('')
.split(',').join('.')
Number('string');
To do on a line 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]
Browser other questions tagged php javascript jquery
You are not signed in. Login or sign up in order to post.
Thanks, thanks it worked!
– Guilherme Costa