skip to Main Content

There are many numbers in my application and I want separate them with commas every 3 digits by CSS or SCSS.

I haven’t found a desired result on Google.
Can anyone help me on this please?

Like:

<span class="number"> 1234567.89 </span>

result:

<span class="number"> 1,234,567.89 </span>

2

Answers


  1. if you can use javascript you can use toLocaleString function

    the function: 1234567.89.toLocaleString()
    
    result: '1,234,567.89'
    

    enter image description here

    Login or Signup to reply.
  2. Try the following code

    const number = document.querySelector('.number');
    
    const formattedNumber = parseFloat(number.textContent).toLocaleString('en');
    number.innerText = formattedNumber;
    .number::after {
      content: attr(data-number);
    }
    <span class="number">1234567.89</span>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search