<div id="newNum"></div>
// 加上千分位的函式
function thousandth(num) {
return String(num).replace(/(\d)(?=(\d{3})+$)/g, "$1,");
}
// 宣告數值
let num = 2023450633;
//抓取網頁元素
const newNumEl = document.querySelector("#newNum");
// 把加上千分位的數字顯示在畫面
newNumEl.innerHTML = thousandth(num);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.