Skip to content

Format numbers with thousand seperator

In most web sites and applications, you’ll find yourself with the task or formatting large numbers properly. With the following snippet, this can be done easily:

const numberWithCommas = (x) => {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

You can replace the , with a seperator of your liking.


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.