Skip to main content
Participating Frequently
Nov 13, 2019 6:23 PM UTC
Answered

HELP with rounding decimals!!

I am doing a rating survey and when the cobination is 1,1,2,2,1,1 the answer is 1.33333

I cannot for the life of me execute a script that will just let it be 1.33

This is what I have entered, what am I doing wrong???

The value is called 's3_result'

var s3_result = window.cpAPIInterface.getVariableValue("s3_result");

var1_decimal = Math.round("s3_result"*100)/100;

window.cpAPIInterface.setVariableValue("s3_result",var1_decimal);

This topic is closed to new replies. Start a new post to keep the conversation going.
Stagprime2687219
Stagprime2687219Correct answer
Legend
Nov 14, 2019 1:58 PM UTC

GOT IT!

This is the action that goes into the Advanced actions after the expression. 'Execute Javascript', put this in the script window and select 'current' for the screen"

 

Thank you for all your help!

 

window.cpAPIInterface.setVariableValue("s4_result",Math.round(s4_result*100)/100);


Glad to hear it is solved.
The solution was much easier once we broadened the scope.

Sequence of operations is very important.

Have a great day!

18 replies

Stagprime2687219
Legend
Nov 13, 2019 6:38 PM UTC

What happens if you take out the quotes here?

 

var1_decimal = Math.round("s3_result"*100)/100;

Translate
Participating Frequently
Nov 13, 2019 6:40 PM UTC

I will check now, I will upload to LMS and be right back

Translate