You need a bit of Javascript to do this, and essentially, since a numeric entry variable can only be a number, the result from Javascript needs to go into a text variable. So you will likely want to do something like hide the numeric entry once it is complete, or open a layer to appear to replace the original with the text variable with commas.
The Javascript I used is below. It runs from a trigger when control loses from the numeric entry field. Note that I just used the default NumericEntry variable that SL creates when you have a numeric entry field.
var player = GetPlayer();
function formatNumber(num) { return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,') }
4 Replies
Hi Paula,
You need a bit of Javascript to do this, and essentially, since a numeric entry variable can only be a number, the result from Javascript needs to go into a text variable. So you will likely want to do something like hide the numeric entry once it is complete, or open a layer to appear to replace the original with the text variable with commas.
I found the function to add the commas here: https://blog.abelotech.com/posts/number-currency-formatting-javascript/
Here's my quick and dirty Storyline version: https://360.articulate.com/review/content/4a06f424-e6ec-4e77-b6a3-b135a4aef143/review
I've attached the SL file.
The Javascript I used is below. It runs from a trigger when control loses from the numeric entry field. Note that I just used the default NumericEntry variable that SL creates when you have a numeric entry field.
var player = GetPlayer();
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
var jsnumeric = player.GetVar("NumericEntry")
var jsnumcomma = formatNumber(jsnumeric)
player.SetVar("Numeric_with", jsnumcomma);
David has the answer, I normally run it when variable changes, but either way it works.
Thanks so much!!
Phil,
I like your way better, keying off a change in variable, as it's more direct.
Thanks!
This discussion is closed. You can start a new discussion or contact Articulate Support.