s/\d{1,3}(?=(\d{3})+(?!\d))/$&,/g

The amount of code that goes in to formatting numbers can be silly sometimes, especially when you realise it can be done as a regex.

Note that if the number has a DP longer than 2, it'll format it - I suggest splitting out the DP first, and bash them back together.

(via)

NewCommand line for non-techies

I've published 37 videos for new developers, designers, UX, UI, product owners and anyone who needs to conquer the command line today.

Want more?

Posts, web development learnings & insights, exclusive workshop and training discounts and more, direct to your inbox.