Say I have a string: 33400298.57
I've written a function (too long, too bloated, too substandard to post here) which formats this into:
33,400,298.57
The meat logic is the insertion of commas - leftwards of the decimal, every three places. Can there be a one line solution using regex to accomplish this? Presently, I'm splitting, reversing, looping to insert, reversing and joining again. Needless to say, it's unoptimal.
I'm looking for something like this:
Random color generator: '#'+Math.floor(Math.random()*16777215).toString(16);
Thanks.