Copy link to clipboard
Copied
Hi,
We are programming a quizz in Adobe Captivate 9. For some reason, we cannot use the quizz function.
We are calculating by ourself the final percentage. For the moment, the variable is returning a value with something like 15 digits (65,546543643974..)
The question is : how is it possible to round the number to a maximum of 2 decimals ?
Tx
Copy link to clipboard
Copied
You'll most likely need to create a variable in Captivate to display the percentage as you cannot overwrite system variables.
In the JavaScript window on enter of the slide where you see the number execute this JS:
var tempVal = Math.round(cpAPIInterface.getVariableValue('percentageVariable");
cpAPIInterface.setVariableValue( "yourVariable", tempVal )
percentageVariable represents the variable you are using in Captivate that displays the decimals
yourVariable represents the new variable you create to display the percentage
Copy link to clipboard
Copied
David, is this not returning an integer, instead of a number with 2 decimals?
Copy link to clipboard
Copied
David, This JS is great!
For the lay person ( like me ). It rounds to an even percentage .
Don’t forget, after copying this JavaScript. You need to make a few small changes or it won't work.
One of my friends pointed out that I needed to:
It works when published HTML5.
Copy link to clipboard
Copied
You're right Lieve, I think I lost part of the script while substituting the Captivate variable setters and getters!
Try this:
var tempVal = parseInt( window.cpAPIInterface.getVariableValue('percentageVariable') )
window.cpAPIInterface.setVariableValue( "yourVariable", tempVal.toFixed( 2 ) )
Copy link to clipboard
Copied
Thanks!
Shouldn't it be 'parseFloat' instead of 'parseInt' to keep two decimals?
Copy link to clipboard
Copied
I always try to make the number of questions and the question points divisible in such a way that you don't end up with fractions. For example, If you have 51 questions someone who gets 45 correct and they are all valued equally, will get a score of 88.23529411... If you simply remove one question, the score becomes 90%.
Copy link to clipboard
Copied
It's working thank you very much for all.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now