Adding commas to long numbers in Storyline
May 16, 2017
I played around with adding commas to long numbers in Storyline to make numbers a bit more readable. Here is the solution:
Here is the JavaScript I used on a JavaScript trigger. I have a variable in Storyline called SLNumber (the number someone types in), one called SLAnswer (the final answer you will get in Storyline), and a JavaScript variable called JSAnswer.
var player = GetPlayer();
var JSAnswer = player.GetVar("SLNumber");
JSAnswer = numberWithCommas(JSAnswer);
player.SetVar("SLAnswer",JSAnswer);
function numberWithCommas(x) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
6 Replies
Love it David - thanks for sharing it here!
Glad you like it, Ashley. I added the story file (Storyline 2) as well if anyone needs it.
Thanks David. 😊
Hey David, great work, thanks! Is there a way to replace the contents of the numeric text field with the comma'd values when the field loses focus?
Fantastic code and explanation! I'm new to javascript and it clarified for me which variables I needed to rename to make it work in my project. Thanks for your help!
Ah, so happy to hear it helped you Nancy!
This discussion is closed. You can start a new discussion or contact Articulate Support.