Forum Discussion
A Solution to rounding in Storyline – without using Javascript
Normal 0 false false false oNotPromoteQF /> EN-US X-NONE X-NONE
I found a way to round numbers in Storyline without using Javascript. The challenge was to show whole percentage numbers from calculated decimal numbers (i.e. 33% for 1/3 and 67% for 2/3). Searching through the forums, all I could find was Javascript solutions and suggestions to submit a feature request. Not happy with either of these answers, I continued to play around.
I found that Storyline only holds 7 digits past the decimal place, and the 7th digit is rounded. So to get a rounded decimal (percentage) as a whole number, divide by 100,000, and then multiply by 10,000,000.
For example:
2 / 3 = 0.6666667 (rounded at the 7th position by Storyline)
0.6666667 / 100,000 = .000006666667 (which is rounded to 0.0000067)
0.0000067 * 10,000,000 = 67
Now we have our rounded 67% from 2/3
You should be able to apply this to any number you want to round. Divide and then multiply by a multiple of 10 that is large enough to push the number you want to round to the 7th position past the decimal (i.e. 13,567 / 10,000,000,000 * 10,000,000,000 = 14,000)
- TomLunzerCommunity Member
Thanks for the tip. I needed to have rounded off percentages for my project.
This really should be an option that can be set in the quiz options.
I posted a feature request.
I am including a zipped up sample of the Articulate Storyline file here for others to see how this was set up. There is also a "Instructions" PDF file included with some screenshots of variables setup. My quiz here uses a number of question banks so the questions are randomized.
To sum up what happens is per previous instructions by Terri and others I have created a few triggers that divide and then multiply the quiz results Percentage score by 10000000. It does this to push the score percentage past the Seven digits limit decimal place.
- AntonioCommunity Member
Hi Tom,
Thanks a lot for sharing in the community how to do the rounding in such a didactic way. You saved my live when i was asked to do that just last day before turning in a project.
I will place a feature request, as you i think this need to be in quiz options.
- GarryGentCommunity Member
Thanks for the file Tom. Great way of solving the problem
- MitchHayashiCommunity Member
Since this does not work in Storyline 360, I found a very easy way to implement a floor flunction in Storyline 360 without using Javascript.
EDIT: Corrected for edge cases and much simplified! Also attached an updated screenshot.
Corrected Steps:
- Create one variable, floorScore, and initialize to 0
Results Slide triggers:
- Set floorScore equal to 100 when the timeline starts
- Subtract 1 from floorScore when floorScore changes if floorScore is greater than Results.ScorePercent
And that is it!
--------------------------------------------
Old (incorrect) version below.
Edit 4/17/2019: I have removed the incorrect version to avoid confusion.
- LaurenFCommunity Member
Hi Mitch,
Thank you for providing this! When we implemented it we realized if we got a perfect score it was rounding down to 99%. I added a trigger between your step 1 and 2 triggers that says Set floorScore equal to Results.ScorePercent if Results.ScorePercent =100, and also added a condition on your step 3 trigger to say if floorScore does not equal 100. This solved the problem for us.
- AkhileshRaoCommunity Member
Hey Mitch and Lauren!
Thanks for sharing the inputs :)
Can you please explain the logic behind the triggers?
- OwenHoltSuper Hero
Divide by 10.000,000 and then multiply by the same.
For those who want the math logic behind this answer,
42.85 / 10,000,000 = 0.0000043 in articulate (dividing by 10,000,000 moves the decimal place 7 places to the left and the 7th decimal position gets rounded)
0.0000043 * 10,000,000 = 43.0 (multiplying by 10,000,000 moves the decimal 7 places to the right resulting in a whole number)
- GauravMittalCommunity Member
Thanks Owen......
- JenniferBarn063Community Member
I ran into a similar issue and I didn't want to spend the time to make this edit since I only had a 3 question quiz so I found a really good alternative!
All I did was change the question scores from the defaulted 10pts (2 to 33pts and 1 to 34pts) and then changed the results display from %Results.ScorePercent% to %Results.ScorePoints%. That resulted in making the results rounded in less than a minute!
- MikeClapper-5daCommunity Member
A colleague shared this very helpful tip that finally solved the issue for me! I created a Storyline number variable called RoundedScore, which I set equal to the Results.ScorePercent as the results slide timeline begins. Then I execute this Javascript:
var player = GetPlayer();
var score = player.GetVar("RoundedScore");
player.SetVar("RoundedScore", Math.round(score));Finally, I changed the "%Results'ScorePercent%%" text on the results slide to "%RoundedScore%%", and it works in Storyline 3! I hope this helps others who want to round the percentage in Storyline 3.
- SimonCCommunity Member
Hey Mike, I tried your method in Storyline 3 and it didn't seem to work for me. Do you execute that Javascript when the timeline starts are is the trigger set up to go off at some other point?
- SYuCommunity Member
Thanks for this Terry! I've included a screenshot in case anyone needs a tip on how to execute this in the slide itself.
Updated 5/14/15 to say: Whoops, my math was wrong on this one! Sorry about that! See other responses for the correct math.
- PhilMayorSuper Hero
Jennifer Barnett said:
I ran into a similar issue and I didn't want to spend the time to make this edit since I only had a 3 question quiz so I found a really good alternative!
All I did was change the question scores from the defaulted 10pts (2 to 33pts and 1 to 34pts) and then changed the results display from %Results.ScorePercent% to %Results.ScorePoints%. That resulted in making the results rounded in less than a minute!
this will only work if your points add up yo 100, because you are no longer showing a percentage, points have to be integers - NancyWoinoskiSuper Hero
Nice Terry. Thanks for this I am going to add it to my arsenal of tricks.
- BrendaHeilmanCommunity Member
Seriously cool, Terry! Thanks bunches for posting!
- BrettRockwoodCommunity Member
Let me start by saying math isn't my strong suit but I can't seem to get this to work properly with the standard variable Results.ScorePercent. For example my score is 42.85% as reported by the Results.ScorePercent variable. I created a new variable called NonRoundScore as S. Yu suggested and set it to equal Results.ScorePercent. I then set triggers to divide it by 100,000 and then multiply it by 10,000,000. But the result of my NonRoundScore variable = 4285%. What I want it to show is 43%. I'm guessing that it is the numbers that I'm multiplying and dividing by but I can't seem to discover what the right combination is to get me to my magic 43%.
Anyone out there who can lend a hand...?