Formatting numeric variables....

Aug 26, 2023

Friends, it's been a number of years since I asked how to format numeric variables, ie commas and decimal place such as $17,200.

Has there been any progress on this in SL after all these years? Or has anyone found a way to do it? I've seen some references to Javascript, but that's not in my skillset, so if that's the only solution, can anyone explain and show examples of how/where to include it in SL? OR does anyone have  something like this that can be purchased???

 

5 Replies
Steve Gannon

Hi Carrie,

There is still no way to format numbers like you want out-of-the-box in Storyline. JavaScript is still the way to go. Here are a couple of forum threads to get you started (though there are many more discussions on this):

https://community.articulate.com/discussions/articulate-storyline/how-to-display-2-decimal-places-in-variable-calculations

https://community.articulate.com/discussions/articulate-storyline/adding-commas-decimals-into-variable-values

If you want to post a single-slide Storyline file containing your specific case, I'll be happy to insert the JavaScript code for you. Just tell me the format you need (whole number? 2 decimal format for cents?).

Jürgen Schoenemeyer

with modern javascript it is not very complicated

part 1: converting the number (based on country code + currency)

function formatCurrency(inNumber){
  return new Intl.NumberFormat('en-US', { 
    style:    'currency',
    currency: 'USD',
  }).format(inNumber);
};

part 2: connection to storyline variables

var player = GetPlayer();

var input  = player.GetVar("NumericEntry");
var output = formatCurrency(input);

player.SetVar("FormatedEntry", output);

result:
https://360.articulate.com/review/content/3da26422-ecc6-4cbf-a097-e74bcad9924b/review

more infos:

Carrie Eaton
Steve Gannon

Hi Carrie,

There is still no way to format numbers like you want out-of-the-box in Storyline. JavaScript is still the way to go. Here are a couple of forum threads to get you started (though there are many more discussions on this):

https://community.articulate.com/discussions/articulate-storyline/how-to-display-2-decimal-places-in-variable-calculations

https://community.articulate.com/discussions/articulate-storyline/adding-commas-decimals-into-variable-values

If you want to post a single-slide Storyline file containing your specific case, I'll be happy to insert the JavaScript code for you. Just tell me the format you need (whole number? 2 decimal format for cents?).

Steve, I would appreciate your help, but is there a way I can send you a SL screen rather than posting it publicly here? It's a client file. I see a way to send you an email here in Heroes but not your actual email. Shall I send you my email that way so we can communicate directly? And no rush on this!