How do this function compute with a comma instead of a dot?

Asked

Viewed 92 times

0

<script type="text/javascript">
$(document).ready(function() {
  $("#somar").click(function(){
    var total = 0;
    var desconto = $("#desconto").val() != "" ? $("#desconto").val() : 0;
    $('.input').each(function(){
      var valor = Number($(this).val());
      if (!isNaN(valor)) total += valor;
    });
    total = total - desconto;
    $(".resultado").html(total.toFixed(2));
  });
});
</script>
<script>
  function imprimir(mesmo){
    var conteudo = mesmo.parentElement.innerHTML,
        tela_impressao = window.open('about:blank');

    tela_impressao.document.write(conteudo);
    tela_impressao.window.print();
    tela_impressao.window.close();
  }
</script>
  • You cannot calculate with COMMA, what you can do is turn the point into a comma in the function return. See the function replace of the JS

  • How do I do that?

  • var str = "5,8"; var str = str.replace(",", ".");

  • Now what part of the code?

  • Let me explain these values already stay in an input that is received from another user I wanted to do after clicking calculate without putting the values in the input!

No answers

Browser other questions tagged

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