Javascript Trigger
Jun 26, 2013
Hi
Could someone please help me with a Javascript trigger to format a number variable:
In my results slide, I would like to format the Results.ScorePercent variable to exclude the decimal numbers. ie from 82,13% to 82%
newResult is a new variable I'd like the answer to go into.
This is what I have (and have tried many other options and variations, with no luck)
var nbre1 = Math.random('Results.ScorePercent');
var player = GetPlayer();
player.SetVar('newResult', nbre1);
Alternatively: what is the formula Storyline uses for the Results.ScorePercent variable? Could I do something with that?
Can anyone help?
Thanks,
Lucia
2 Replies
I don't understand why you would want to use the Math.random method, which is meant to return a random number, NOT a rounded value. Based on your description, you should use the Math.round method.Some info on this here.
Lucia
Jus found this. Has a similar problem
// After getting your variable
var player = GetPlayer();
var nbre1 = Math.floor(player.GetVar('Results.ScorePercent'));
player.SetVar('newResult', nbre1);
Should work. Note you need to get the Results.ScorePercent from the player, than round it down to drop the decimal.
If you want you can use the ceil() function to round up.
This discussion is closed. You can start a new discussion or contact Articulate Support.