add separator for thousands jquery code example
Example 1: js format number thousands separator
function numberWithCommas(x) {
return x.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",");
}
Example 2: javascript round to 2 digits
var num = 2;
var roundedString = num.toFixed(2);// 2.00