Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adobe Captivate 9 : rounding to the last 2 decimals

New Here ,
Nov 22, 2016 Nov 22, 2016

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

1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 22, 2016 Nov 22, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2016 Nov 22, 2016

David, is this not returning an integer, instead of a number with 2 decimals?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2018 Feb 08, 2018
LATEST

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: 

  1. Change the double quote in at the end of (‘percentageVariable”) to a single quote mark.
  2. Add another parentheses after (‘percentageVariable’)) but before the semi colon.
  3. End line two ( "yourVariable", tempVal ); with a semi colon.    

It works when published HTML5. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 22, 2016 Nov 22, 2016

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 ) )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 22, 2016 Nov 22, 2016

Thanks!

Shouldn't it be 'parseFloat' instead of 'parseInt' to keep two decimals?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2016 Nov 22, 2016

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%.

Paul Wilson, CTDP
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 01, 2016 Dec 01, 2016

It's working thank you very much for all.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources