JS
(quick guide & examples)
THE NUMBER var num = 1234567.89;
ADD COMMA & CURRENCY -¥1,234,568 c = num.toLocaleString("ja-JP", { style: "currency", currency: "JPY" });
ADD COMMA - 1,234,567.89 var c = num.toLocaleString("en-US");
THE NUMBER var num = 1234567.89;
INSERT COMMAS - 1,234,567.89 c = replace(/\B(?=(\d{3})+(?!\d))/g, ",");
CONVERT TO STRING var c = num.toString();
NUMBER TO STRING var num = 12345.78, dec = ".00"; num = num.toString();
EXTRACT DECIMALS (IF ANY) var dot = num.indexOf("."); if (dot != -1) { dec = +("0" + num.substring(dot)); dec = dec.toFixed(2).toString() .substring(1); num = num.substring(0, dot); }
ADD THOUSAND SEPARATORS if (num.length>3) { let temp = "", j = 0; for (let i=num.length-1; i>=0; i--) { temp = num[i] + temp; j++; if (j%3==0 && i!=0) { temp = ","+temp; } } num = temp; }
RESULT - 12,345.78 num = num + dec;