Decimal Display

Hi! Thanks in Advance!

I understand that the default SL functionality is to display 2 decimal places for number variables. Does anyone know if there is anything that can be edited within a scorm file to display 4 decimal places (rounded) by default? I've seen some workarounds, but they seem cumbersome to do if you were to be working on a math/finance type course with specific rules around decimals and rounding that includes several equations and a large number of problem sets.


5 Replies
Matthew Bibby

Thanks Traci. I responded to your email but I'll share this here as well in case in helps someone in the future.

Here is a demo.

Here is the source file.

Here is the JavaScript used to achieve this:

var player = GetPlayer();
var num = player.GetVar("NumericEntry");
var num=parseFloat(num).toFixed(4);
var txt=num.toString();
player.SetVar("FourDecimals", txt);

For this to work, you'll need the following variables in Storyline:

NumericEntry - which is a number variable. This is where the original number is entered.
FourDecimals - which is a text variable. This is where the four decimal number is saved.

Here is a quick description of what's happening in the above JavaScript:

var player = GetPlayer(); // Establish communication with Storyline
var num = player.GetVar("NumericEntry"); // Create a new JS variable called num and populate it with the value of the Storyline varialbe NumericEntry
var num=parseFloat(num).toFixed(4); // Makes the num variable a floating point number and limits it to 4 decimals
var txt=num.toString(); // Converts the above number to a text string
player.SetVar("FourDecimals", txt); // Passes the text string back to the Storyline variable FourDecimals.

This solution isn't perfect.

The variable that we get back to Storyline is a text variable rather than a number variable, which means you can't then perform math related functions with it in Storyline.

In theory, this shouldn't be required, we should just be able to change the fourth line from var num=parseFloat(num).toFixed(4); to var num=num.toFixed(4); and then pass that value back to a numeric variable in Storyline. However, when I tried this approach the script wouldn't run. I also tried another approach where I used a different approach to feed the number variable back to a numeric variable in Storyline but in that case, Storyline just made it a two decimal number!

However, when I tried this approach the script wouldn't run as it claimed that num.toFixed was not a function. I suspect that Storyline may have been passing the original variable as text rather than a number...

I also tried another approach where I passed a number back to a numeric variable in Storyline but Storyline decided to just make it a two decimal number!

Silly Storyline.

Hope this helps.

Zsolt Olah

It is actually even more mysterious. Let's say you have your number you enter as 1.1399. Once this gets into the SL variable, it's rounded to 1.14. BUT it is not the actual number stored in Storyline, it is just the number DISPLAYED. 

You can test this by multiply the number (supposedly 1.14) by 1000 in JavaScript and you get 1139.9. That means SL keeps the actual 1.1399 number in the variable, it just doesn't show it.