Forum Discussion
HappilyCreative
3 years agoCommunity Member
How to Get Two Decimal Places or Cut Decimals with JavaScript in Storyline?
Hi,
I am trying to figure out how to get my number variable to either have two decimal places, or simply have the decimals cut and just round to the nearest whole number. I was able to achieve ge...
HappilyCreative
3 years agoCommunity Member
I have JavaScript working to add a comma to the number variable. This is what that current JS looks like:
var player = GetPlayer();
var JSAnswer = player.GetVar("TotalSaved");
JSAnswer = numberWithCommas(JSAnswer);
player.SetVar("TotalSavedTxt",JSAnswer);
function numberWithCommas(x) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}