Forum Discussion
Formatting numeric variables....
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???
- SteveGannonCommunity Member
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):
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?).
- CarrieEatonCommunity Member
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!
- Jürgen_Schoene_Community Member
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/reviewmore infos:
- CarrieEatonCommunity Member
Jurgen, I appreciate your input! But having zero experience with Javascript, this still looks complicated to me. ;-) I'm hoping that Steve will be able to help per his response above. Thank you!
- SteveGannonCommunity Member
Send me a private message, Carrie, and I'll respond with my email so you can send me your file.