0

I have this code and I want to show the price_final var with comma and currency

Here is my code:

$(document).ready(function() {
  var prices = $('span.product_weight').text()
  $("input").change(function() {
    var price = '';
    var quantity = parseInt($('input[name=quantity]').val());
    console.log(quantity)
    var price = prices.replace(/[^\d-]/g, '');
    var price_final = price * quantity;
    $('span.product_weight').html(price_final);
  });
});
isherwood
  • 52,576
  • 15
  • 105
  • 143
  • What is the input and expected output? – Mitya May 12 '20 at 12:56
  • The input is int (1000000) and I want to output be like this : 1,000,000 – Mehran Pourjenabi May 12 '20 at 12:57
  • Also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString – freedomn-m May 12 '20 at 12:58
  • @freedomn-m How can I put the final number into a var?! – Mehran Pourjenabi May 12 '20 at 13:01
  • Not sure I understand what you mean by "put into a var" - `var x =` seems too trivial for you to be asking that, surely? `var price_final = (price * quantity).toLocaleString();` - or better, just use it: `var price_final = price * quantity; $('span.product_weight').html(price_final.toLocaleString())` ( – freedomn-m May 12 '20 at 13:05

0 Answers0