Skip to main content
nicolas-hsj
Known Participant
November 22, 2016
Question

Adobe Captivate 9 : rounding to the last 2 decimals

  • November 22, 2016
  • 4 replies
  • 1612 views

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

    This topic has been closed for replies.

    4 replies

    nicolas-hsj
    Known Participant
    December 1, 2016

    It's working thank you very much for all.

    Paul Wilson CTDP
    Community Expert
    Community Expert
    November 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
    TLCMediaDesign
    Inspiring
    November 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 ) )

    Lilybiri
    Legend
    November 22, 2016

    Thanks!

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

    TLCMediaDesign
    Inspiring
    November 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

    Lilybiri
    Legend
    November 22, 2016

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