Forum Discussion
Getting variable and rounding up with Java script
Trying to take a variable and rounding it up to the nearest thousand. Can someone help with the code.
player.GetVar("Life7074");
var Num = "Life7074;
var val = Math.ceil( num / 1000) * 1000);
player.SetVar("Life7074",val);
5 Replies
- RussellKillips-Community Member
Here's the code that should work. I have also attached an example story file for you to take a look at.
var player = GetPlayer();
var num = player.GetVar("Life7074");
var val = Math.ceil(num/1000)*1000;
player.SetVar("Life7074",val); - Jean-MarcPruneaCommunity Member
Thank you. It worked perfectly
- Jean-MarcPruneaCommunity Member
Maybe you can help wit this:
var player = GetPlayer();
var num = player.GetVar("ldt");
if ((num*0.6667) < 2625) {
var val = Math.round(num*0.6667);
} else {
var val = Math.round(2625+(((num*0.667)-2625)*.5)) ;
}player.SetVar("LDT",val);
- RussellKillips-Community Member
I’m not at work today. But from taking a quick look, I see that ldt is all lowercase in line 2 and LDT is capitalized in the last line.
Javascript is case sensitive. Make sure the variable name matches how you have it declared in your storyline variables.
- Jean-MarcPruneaCommunity Member
var player = GetPlayer();
var a = player.GetVar("Anualsallary");
var P = player.GetVar("KF5");
var r = .05;
var n = 12;
var z = r / n;
var u = 1 + z;
var t = 25;
var y = n * t;
var m = a / 12 * .08;
var val = ( P * Math.pow(u, y)) + (m * Math.pow(u, y) - 1) / z);
player.SetVar("KF10",val);
Related Content
- 10 months ago
- 11 months ago
- 11 months ago