Search code examples
javascriptnumber-formatting

Group numbers in sets of three to make them more readable


I have a site with lots of large numbers like this:

154568545
8516548964
455656

to make them more readable I would like to group the digits into sets of three like this:

154 568 545
8 516 548 964
455 656

Is there a way to do this?


Solution

  • I'm not exactly sure what you want, you might want to be a bit more specific, but toLocaleString might be an interesting option for you.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString.