# A Solution to rounding in Storyline – without using Javascript

Jun 06, 2013

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 7^{th} 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 7^{th} 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)

## 99 Replies

Shouldn't it be .toFixed(2) for 2 decimal places

Sent from my iPhone

Well I should read the post change to a 0 should give an integer

Sent from my iPhone

I ended up just creating the variables and dividing then multiplying them. It worked like a charm.

All you seriously have to do is delete the first set -

%Results.ScorePercent%%- and then remove the parentheses and then all you get is the total amount of points. Hope this helps! AllisonPlease does anyone know if the number of decimal places stored has changed? I have published a course in Storyline 1 before and using the dividing/multiply method and all worked fine. Have now published from Storyline 2 and I get the two decimal places again. Also, I am now using HTML5 output. Thanks

Hi,

As someone who doesn't really know much about Javascript, I'm trying to figure out how to solve a problem I'm having. In our course, we have a variable that we are displaying on each page to show the % complete. We did the divide by 10,000,000 then multiply by 10,000,000 and it's working fine non-mac devices. However Macs are still displaying the two decimal places and we want to get rid of that. So, I tried to add this JS after my % visited variable is calculated and it's not working.

Here is what I added:

var player = GetPlayer();

var numValue = GblScreensVisitedPercentage

var JSRoundedNum = numValue.toFixed(1);

player.SetVar("RoundedNum",JSRoundedNum);

Any thoughts would be greatly appreciated!

Wow. I was skeptical, but this worked great! Thank you soooooooo much.

Why couldn't you perform your math functions followed by the division and multiplication at the end to get the whole number. You could also use a condition to say if the answer is >10, you subtract one of the 0's, still allowing you to use the program without JS.

ex. answerNum / 100000 x 10000000 if answerNum<10

then another trigger that says answerNum / 10000 x 10000000 if answerNum>=10

The concept should be true. I'd have to actually play with the numbers to make it work exactly, but these kinds of triggers are definitely doable.

This works fine in flash version but not in html5 version

Does anyone have specific screen shots on how to do round the percentage? I really can't seem to work out how to do this.

Thanks!

I tried applying this JavaScript and it doesn't seem to work. I have an answer that shows as (i.e.) 10.454240362 and I want it to round up to 10.45

How can I apply a variable/JavaScript to make this work?

Thanks

Sandy

I've tried this method in Storyline 3, and it doesn't seem to work. I still get a percentage down to the hundredths. I've even taken the divide/multiply operation to the maximum number of characters to no avail.

I tried copying some Javascript as well. I created a trigger to execute the following Javascript command: Math.round(Results.ScorePercent);

This did not work, either.

Any suggestions?

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.

This post was removed by the author

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?

this only seems to round up to one decimal place not to a whole number am i missing something?

my result = 28.57%

after javascript = 28.6%

I just tested the JavaScript and it worked as it should for me. Here are a few things to remember:

1) you can't change the StoryLine quiz variables directly. You need to set up your own variable in StoryLine and set it equal to the appropriate StoryLine quiz variable. You can then modify/manipulate your variable.

2) Order matters. Set you variable value equal to StoryLine's quiz variable 1st; as soon as the timeline starts.

3) The timeline you should be using is the slide's timeline.

4) Remember that JavaScript is case sensitive. Also, it is easier to troubleshoot if you perform steps 1 at a time. You will notice that my code performs the math round on its own line before sending the result to StoryLine. This isn't required but makes the code easier to follow and understand and facilitates debugging.

Sandy,

You would use something like the following:

var player = GetPlayer();

var num = player.GetVar("Your StoryLine Variable");

num = Math.round((num + 0.00001) * 100) / 100;

player.SetVar("Your StoryLine Variable", num);

I tested this with a short 6 question quiz. I wanted to see how the rounding would effect the actual quiz results. I made the passing percentage 67%. In testing I got 2 wrong and 4 right in which without rounding would produce a score of 66.66%. I am able to get the score percent to show as 67% and the passing percent shows as 67% but the result slide shows as fail. Am I doing something wrong?

This is why I don't recommend traditional rounding. Technically, if the user scored 66.66 they did fail. They were close, but they failed. Rounding up to show them 67 on a results slide gives them the impression that they reached the goal when they didn't. StoryLine won't let you access the hard wired quiz results that get passed to the LMS so they will show as failed there. The rounding only manipulates the score that is displayed but not the actual result that is used by the course.

The non traditional rounding method of always rounding down is probably the better practice here. I would recommend using Math.floor(score); in the code instead of Math.round(score);

Math.floor(); will return the number representing the largest integer less than or equal to the specified number.

Math.floor( 66.66); will return 66 and the user fails.

Math.floor( 66.99); will return 66 and the user fails.

Math.floor( 67 ); will return 67 and the user passes.

Math.floor(67.66); // will return 67 and the user passes.

Math.floor(67.9999); // will return 67 and the user passes.

Thank you for this explanation. I will try the Math.floor code that should work for me.

Hi!

Old but usefull thread. I´m trying to use it in Storyline 360 and it seems that it´s not working anymore. The number rounds up in storyline 2 but the same source file opened in 360 doesn´t work (it always shows two decimal numbers). Is there another workarround? Thanks!

Thanks Owen......

I'm in the same boat as Miriam - In need of this, but it doesn't work in SL3 either - Anyone have any miracles?

As long as you are not using the mobile player, JavaScript is your friend for rounding.

StoryLine 3/360 now support an infinitely long decimal making the old math round solution obsolete.