1000 -> $1,000 reactive variable?

Hi folks, I have a database object called player_credits

I’m running a JS to transform that to currency. It works fine.

	$(this).html( $(this).html().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") ); 

I’ve set this in a loop of every 100ms

But the problem is it then becomes $1,000$1,001 when I add 1 to it. Then $1,000$1,001,$105 when I add 4 more.

What’s the right way to do this?

Solved it.

I made a helper for player_credits, which had the inline HTML for my class.

This redraws the HTML correctly and my script picks it up. Ez.

You may want to have a look at something like http://numeraljs.com

1 Like

Nice this is kinda what I was looking for. Cheers,