Javascript - Formatting to an "n" decimal place

Good Day all,

So, have a look at the below code. Basic JavaScript code, however, I'm at the stage whereby I'm suspecting a limitation in Storyline (perhaps I'm wrong):


var gPlay = GetPlayer();

var T1 = gPlay.GetVar("intT1");
var T2 = gPlay.GetVar("intT2");
var intR = T1 / T2;
intR = intR.toFixed(3); //format the result in intR to 3 decimal places

gPlay.SetVar("intResult1", intR); //pass the formatted value of intR to intResult1


I want intR to be equal to 0.155

If I insert an alert statement showing the value of the variable intR, I get 0.155. Works perfect!

However, when I check the value of intResult1 (which is a variable defined in storyline), I get 0.15

I used the following functions and none of them seem to work:



What's up with this? Is my code incorrect by any chance? For some reason when I'm passing the formatted value (0.155) to the variable (intResult1), it's losing one decimal place, i.e.: 0.15 and not 0.155


1 Reply
Shawn Lalla

Ok - It's a Storyline limitation. Strange that Storyline cannot handle exponential numbers. Math.pow(x, y) is handled well through JavaScript, Storyline is really bad at receiving the exponential value. Another example (limitation) is that a number such as 1.000635881235 would be passed to Storyline as 10006358812.35. Terrible handling.

Solution - store the value from JavaScript into a Storyline text variable, however, you won't be able to use the value stored in a text variable and use it in a calculation.

Hope this helps. Cheers