Calculate with comma and dot with Jquery

-1

Personal like that I calculate example 1.400 + 1.400 I would like the result to be the following result = 2800 and not 2.8 can anybody help me there?

  $('input[type="text"]').keyup(function(){
                var val = $($(this)).val().replace(',','.');
                $($(this)).val(val);
                $('#result').val(Number($('input[name="number_01"]').val()) + Number($('input[name="number_02"]').val()));
            });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><formaction="">
          <label for="">Peso 01: </label>
          <br>
          <input type="text" name="number_01" id="number_01"><br>
          <label for="">Peso 02: </label>
          <br>
          <input type="text" name="number_02" id="number_02"><br><br>
          <label for="">Resultado: </label>
          <br>
          <input type="text" name="result" id="result">
</form>
    
asked by anonymous 23.08.2018 / 10:36

1 answer

0

Try making the modifications below in your code that will work the way you want.

$('input[type="text"]').keyup(function(){
    //Receber os 2 valores, substituir vírgulas por ponto (replace) e converter para float (decimal)
    var num1 = parseFloat($('#number_01').val().replace(',','.'));
    var num2 = parseFloat($('#number_02').val().replace(',','.'));
    //Somar os valores digitados e exibir o resultado preservando 3 dígitos após o ponto
    $('#result').val((num1 + num2).toFixed(3));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><formaction="">
          <label for="">Peso 01: </label>
          <br>
          <input type="text" name="number_01" id="number_01"><br>
          <label for="">Peso 02: </label>
          <br>
          <input type="text" name="number_02" id="number_02"><br><br>
          <label for="">Resultado: </label>
          <br>
          <input type="text" name="result" id="result">
</form>
    
23.08.2018 / 13:28