I have found articles regarding rounding (mainly multiply/divide by 1000000) but it doesnt work for me. I am not using a results slide. I am creating a conversion for Fahrenheit to Celsius and the math gives me a decimal. I have tried to incorporate the math above, but it still gives me the decimal. Does it only work on the results slide or is there another method?
Hello! This is what I use to round - add a trigger to execute this Java.
I usually have a variable that contains the answer, then I pass it to another variable, then run it though this script. NumberYearCalc is my answer that was passed. And RNDofNumberYearCalc is my new variable that the rounded number will be passed to.
var player = GetPlayer();
var JSRounded=Math.round(player.GetVar("NumberYearCalc"));
I tried Mary's script on a project, and something weird's happening. Each number under Income is multiplied by the Rate to determine Tax. It works fine for the 1st row. It rounded the result up as desired. However, when I started inputting a number into the next field, NaN popped up. Everything worked fine before I used the javascript, so it's not a matter of mistakenly using a text field instead of a number field. Here's the screenshot, and I'm also attaching the story file.
Just noticed because you are using add rather than assign clicking in the files and clicking out without changing the values is calculating and making everything wrong. I would change most of the adds to assign
NaN means not a number. So if you are getting that it could be that the java is outputting a variable that is a text not a numeric. Which if you then took that and tried to do a calculation on would return a NaN.
12 Replies
Hello! This is what I use to round - add a trigger to execute this Java.
I usually have a variable that contains the answer, then I pass it to another variable, then run it though this script. NumberYearCalc is my answer that was passed. And RNDofNumberYearCalc is my new variable that the rounded number will be passed to.
var player = GetPlayer();
var JSRounded=Math.round(player.GetVar("NumberYearCalc"));
player.SetVar("RNDofNumberYearCalc",JSRounded);
Thank you... I will give it a try.
Thank you Mary... it is working beautifully!!
Awesome!!
I tried Mary's script on a project, and something weird's happening. Each number under Income is multiplied by the Rate to determine Tax. It works fine for the 1st row. It rounded the result up as desired. However, when I started inputting a number into the next field, NaN popped up. Everything worked fine before I used the javascript, so it's not a matter of mistakenly using a text field instead of a number field. Here's the screenshot, and I'm also attaching the story file.
Not sure why I added your numbers and got this
I do think you could get away with the reset button if you assigned values instead of adding them
Just noticed because you are using add rather than assign clicking in the files and clicking out without changing the values is calculating and making everything wrong. I would change most of the adds to assign
I only assigned the javascript to the first row of numbers.
I'll try changing the adds to assigns. Thanks!
NaN means not a number. So if you are getting that it could be that the java is outputting a variable that is a text not a numeric. Which if you then took that and tried to do a calculation on would return a NaN.
The rounding seemed to work fine and shouldn't be affecting those lines as the javascript did not apply to them
I changed the adds to assigns and it got rid of the js issue. Thanks!
This discussion is closed. You can start a new discussion or contact Articulate Support.