Appear two decimal places

-1

In this code I have, when value reaches 200.00 ... it shows 200, when it has decimal places, it shows the decimal places ... 200.55 = 200.55

However, I need it to show the two decimal places even if it is "10.00", "00" after the dot ...

Another thing is that I need to appear "," from time to time in the print of the site

I thought of putting it, but I do not know where it would go ...

            total = parseFloat(total.toFixed(2));

jQuery(document).ready(function() {
    jQuery('select[name="service[]"]').change(function() {

        let selects = jQuery("select[name=\"service[]\"]");
        let total = 0;
        
        /* Percorre todos os select */
        $(selects).map(function(i, e) {
          let values = $(e).find(":selected");

       
          /* Percorre todos os valores selecionados */
          $(values).map(function(k, j) {
            total += parseFloat( $(j).data('price').replace(",", ".") );
          });
        });

        $("#preview_value").text(total);

    });
});  
    
asked by anonymous 17.05.2018 / 04:20

1 answer

1

Try this:

 var total = 200;
 console.log(total.toFixed(2).replace(".", ","));

Edit. I've added an example to better illustrate.

$('#numero').keyup(function(){
    $('#conversao').text(parseFloat($('#numero').val()).toFixed(2).replace(".", ","));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text" id="numero"/>

<p id="conversao"></p>
    
17.05.2018 / 04:29