Remove 'R $' before converting to Double

0

I have a list of products in a table, and in order to leave the interface more friendly, in the column 'price' concatenei the 'R $' next to the value. Now I need to capture this value to do a math operation and need to convert to float:

 //captura o valor da linha na table
var linha = $(this).parent('td').parent('tr');
// deve converter o valor para Float
var valor = parseFloat(linha.find('td:eq(1)').text());

Using Jquery, how do I remove the 'R $' characters and convert the value to Float?

    
asked by anonymous 09.01.2018 / 22:09

1 answer

0

Try this answer :

var linha = $(this).parent('td').parent('tr');
var valor = Number(linha.find('td:eq(1)').text().replace(/[^0-9\.-]+/g,""));
    
09.01.2018 / 22:12