Skip to main content
Participating Frequently
November 13, 2019
Answered

HELP with rounding decimals!!

  • November 13, 2019
  • 1 reply
  • 1489 views

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 has been closed for replies.
Correct answer Stagprime2687219

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!

1 reply

Stagprime2687219
Legend
November 13, 2019

What happens if you take out the quotes here?

 

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

Participating Frequently
November 13, 2019

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