Forum Discussion
Calculating trig functions to more than two decimal places in javascript
The problem isn't that the functions are not calculated to a higher precision, but that Storyline only displays 2 decimals in its numbers. You can output your JavaScript calculations to the developer console (F12) to see the larger value. For example:
console.log(Math.tan(radians));
If you want the longer value in Storyline, then you can use a text variable to retain additional decimal places. The toFixed() function also outputs a string rather than a number, so it's better suited to return to a SL text variable as well.
As you probably know, you can't use text variables in SL for calculations, but you probably aren't doing those inside SL anyway. If you pass any text values to JavaScript for numeric calculations, you need to make sure they are converted to numbers before using them. For example, let's say you use
GetPlayer().GetVar("myValue");
to retrieve the text value "4.53453287" from SL. To ensure this is a value and not a string in JavaScript, you can use a statement like
Number(GetPlayer().GetVar("myValue") || 0);
which returns either the numeric conversion of the string, or 0 if the string doesn't represent a number. Otherwise, you risk creating concatenated strings when doing things like addition in JavaScript.