Format monetary fields

Asked

Viewed 21 times

0

I have a field that contains a mask:

inserir a descrição da imagem aqui

But I need him to stay that way in return:

1212.12

I tried with the code below, but it didn’t work:

HTML

<input type="text" name="Valor" id="valor">

Jquery

var nValor = $("#valor").val().split('R$');
var novo = nValor[1].formatMoney(2, '.', ',');
  • 1

    Has a Jquery plugin that does this ai: https://github.com/plentz/jquery-maskmoney

  • 1

    Or you want to do it on your arm?

  • Hello Everson. On the arm would be very complicated? As it would be for just a small snippet of code and on a single page.

1 answer

0


I was able to solve it this way:

var valor = "R$ 11.000,00";
var nValor = valor.val().split('R$');
moedaFloat(nValor);
function moedaFloat(valor){
         moeda = moeda.replace(".","");
         moeda = moeda.replace(",",".");
         return parseFloat(moeda);
   }

Browser other questions tagged

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