Forum Discussion

MariaGonzalez-S's avatar
MariaGonzalez-S
Community Member
5 years ago

Decimal places in Storyline using Javascript

I have a project that works great but I created a different project and I can't figure out what is happening.  It won't take the decimal points.

Help

  • Great! I love a mystery. My guess (based on the title) is that you have a project with a javascript, and that when you  run it, it is supposed to return some numbers formatted with a certain number of decimal places. Am I close?

  • If I guessed right, you have to return the number to SL into a text variable. if you send it back as a number, SL does its own formatting, which you might not like.

  • If you need more than 2 decimal places or fixed decimal places I would return as a string into a text field.

  • Has anyone found a fix besides feeding the numeric into JS and THEN converting to a string? I can use JS and in the console it does show that as a numeric (var jsPortfolioPrev = parseFloat(player.GetVar("gPortfolioPrev")).toFixed(2);) , it's carrying 2 decimals, but once it's fed back into SL, it rips the last one out if it's a "0" (so I can console.log and see "$25.50", but once it goes back into SL, the value shows "25.5". 

    This is problematic when you NEED a numeric for the calculations AND have (and are showing) like 16-20 on a page AND these all feed off each other. Carrying extra variables is a mess to deal with when you have complex calculation logic, and have to weed through extra variables in build and testing just because these decimals are taken out (and for what really??)

    I create a huge amount of finance courses and yes, we do need to see decimals -- even if it's the "0" in 25.50. We also need to run calculations, and check greater and less than - so we do have to use numeric variables. 

    I've even trolled the DOM to see if there's anything I can do as a hack - er - 'workaround' to even make these changes when the page loads, but that's not been successful, either (and in some cases, unless I was insanely systematic, in some cases it would alter some values that I don't want changed - like some numbers that carry no decimals).

    I see there are a number of threads on this, going back like 7 years, so I figured I'd toss this out if there's a lucky chance that in the future someone will find a solution.