How do I style numbers?

后端 未结 2 601
粉色の甜心
粉色の甜心 2021-01-21 08:33

I am trying to change the styling of numbers.

  • I want to add some space between every 3 digits.
  • I will know exactly where the numbers will be located in t
2条回答
  •  借酒劲吻你
    2021-01-21 09:12

    Try something like this.

    const numberWithSep = (x) => {
      return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "
    "); } var num = numberWithSep('12345678'); document.getElementById("number").innerHTML = num; //retrive like this console.log(document.getElementById("number").innerText);
    .sep {
      display: inline-block;
      padding: 10px;
    }

    If you want the separator as comma (,) just change the div to ,

提交回复
热议问题