Remove 'R$' before converting to Double

Asked

Viewed 62 times

-1

I have a list of products in a table, and in order to make the interface more friendly, in the column 'price' I awarded the 'R$' next to the value. Now I need to capture this value to do a mathematical 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?

  • parseFloat(linha.find('td:eq(1)').text().replace('R$','')) can’t?

1 answer

-1


Tries that answer:

var linha = $(this).parent('td').parent('tr');
var valor = Number(linha.find('td:eq(1)').text().replace(/[^0-9\.-]+/g,""));
  • The answer may work, but by putting "try" you are not giving an accurate answer. In addition to not explaining what has been proposed.

  • 1

    Thanks @rLinhares, your comment above did not resolve, but helped to direct my doubt. So that other developers can use I found a link that has the function of converting a String(currency) value to a float and the reverse also: https://www.vivaolinux.com.br/script/Funcoes-para-converter-de-moeda-para-float-e-viceversa

Browser other questions tagged

You are not signed in. Login or sign up in order to post.