How to get number variables to format with comma for thousands

Hello everyone,

Does anyone know how to convert number variables into a format that represents a comma for numbers greater than 1,000?

I currently have three number variables in my project (SliderVar01, SliderVar02 and SliderVar03). These numbers increase as the learner moves the slider, with some calculations going into the 10,000s. 

Any help would be greatly appreciated.

Thanks

1 Reply
Matthew Bibby

Hey mate - this should do the trick:

var player = GetPlayer();
var num = player.GetVar("NumberVariable");
var res = num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
player.SetVar("TextVariable",res);

This assumes that you have a number variable called NumberVariable and a text variable called TextVariable. 

Here is a demo

Here is the source file

And here is a question for Articulate... In the above file, I created a number variable and gave it a default value of 99999999999999. Why is this number being rounded up to 100000000000000 when displayed in a numeric entry box?