In order to add commas to a number string I’m using the following:
someNum.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",")
I need to do one extra thing. I need to wrap everything to the left of the comma (all numbers representing thousands or above in a span tag in order to color those numbers.
So if someNum is 42221 the output whould be <span class="someColorClass">42</span>,221 and if someNum was 221 the output would be 221.
Thanks!
I don’t know if its the most efficient way, but this works: