Formatting numeric entries over 1,000 - need that comma

Jul 02, 2019

Hi all,

How do I get numeric entries over a thousand to include the comma separator? The learner needs to enter 1500 and it appear as 1,500.

Thanks in advance,

Paula 

4 Replies
David Schwartz

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);

 

 

This discussion is closed. You can start a new discussion or contact Articulate Support.