Math rounding problem
November 30, 2011 12:00 AM
Hi,
I have a test of 110 questions. I want to display the number of correct questions on feedback page. But Lectora only calculates percentage. What I need to do is to multiply that score by the number of questions and round it.
1. Multiply percentage score by 110
2. Divide result by 100
3. Round the result.
I have a problem with rounding the variable - it simply does not work.
Here's the bug trace:
Action [OnShow_multBy11 on QuizCount] fired!
readVariable for SB_test_Score = [1]
saveVariable for SB_test_Score to [110]
Action [OnShow_divBy10 on QuizCount] fired!
readVariable for SB_test_Score = [110]
saveVariable for SB_test_Score to [1,1]
Action [OnShow_roundVar on QuizCount] fired!
saveVariable for SB_test_Score to [1,1][/CODE]
Any help is really appreciated![CODE]Action [OnShow_multBy11 on QuizCount] fired!
readVariable for SB_test_Score = [1]
saveVariable for SB_test_Score to [110]
Action [OnShow_divBy10 on QuizCount] fired!
readVariable for SB_test_Score = [110]
saveVariable for SB_test_Score to [1,1]
Action [OnShow_roundVar on QuizCount] fired!
saveVariable for SB_test_Score to [1,1][/CODE]
Any help is really appreciated!
Discussion (2)
@ssneg 43851 wrote:
I ended up including 3 lines of JS for rounding instead of a bunch of Lectora actions.
How did you do that? We have many calculations which get sometimes results like 23.299999767867876868. We need to remove all possible decimals.
parseFloat("123.45601010101231234344").toFixed(2); // ---> "123.46"
Discussions have been disabled for this post