-1

I am doing a calculation and the result from that operation goes into an input text, many times the result comes in thousands and I want to show them with a "," for example insted of 100000 it must show 100,000 but I can't find something that fits my proyect, someone have an idea ?

//Here I do the math
function calcular_total() {
    importe_total = 0    
    var totalC = 0 
    $("#table1 #tb1 .item").each(function (){         
        var ku1 = $(this).find('.precio').text().replace('$', ''); 
        var ku2 = $(this).find('.importe .imp').val();
        totalC += ku1*ku2;
    });
    $("#total").val(totalC.toFixed(2));
} 

//The result goes here
<label style="font-family: 'Raleway', sans-serif;" for="total">Total: </label> <span class="currencyinput">$<input type="text" id="total" name="total" value="0" readonly/></span>
Pevara
  • 14,242
  • 1
  • 34
  • 47
  • `$("#total").val(totalC.toFixed(2).toLocaleString("en"))` – Akam May 24 '16 at 21:19
  • http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript – sinisake May 24 '16 at 21:21
  • Possible duplicate of [How to print a number with commas as thousands separators in JavaScript](http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) – Bijan May 24 '16 at 21:21
  • Possible duplicate of [Add a thousands separator to a total with Javascript or jQuery?](http://stackoverflow.com/questions/2646385/add-a-thousands-separator-to-a-total-with-javascript-or-jquery) – demo May 24 '16 at 21:28

1 Answers1

0

I solved it, I used the ToLocaleString as AKAM said but in this way

totalC1 = totalC.toLocaleString("es-MX",{style:"currency", currency:"MXN"})
$("#total").val(totalC1);

and that's it, it is solved, I hope help someone :)