79394002

Date: 2025-01-28 13:38:53
Score: 1
Natty:
Report link

In JavaScript with regex:

var result_to = document.querySelector('.my_example_280124');
var product_price = 123;
var product_quantity = 67;
var product_total_price = product_price * product_quantity;

// Adding a comma to the result number
product_total_price = product_total_price.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,')

result_to.innerHTML = 
'<p>' + 'Product price: ' + product_price + '</p>' +
'<p>' + 'Product quantity: ' + product_quantity + '</p>' +
'<p>' + '<b>' + 'Product total price: ' + '</b>' +  product_total_price + '</p>';
<div class="my_example_280124"></div>

From: http://www.kompx.com/en/add-thousands-separator-into-numbers-javascript.htm

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: BonMoDo