Skip to main content
Participant
March 25, 2024
Question

Variables not keeping decimal places when relaunching course

  • March 25, 2024
  • 1 reply
  • 452 views

Hello,

When the user clicks on a button, it simply assigns a variable that I've created with 2.5.
It works fine. But when the user exits the course and then reenters (on moodle), the variable just shows 2. I'm using Captivate 11 (2019).
Any idea why this is happening?
Thank you

    This topic has been closed for replies.

    1 reply

    Lilybiri
    Legend
    March 25, 2024

    To format a number correctly, you'll need to use JS.

    Have a look at this blog post, at the end you'll see the JS function which I used to have the correct number of decimals. Captivate has no way to achieve this directly:

    https://blog.lilybiri.com/percentage-progress-indicator-non-linear-course-solution-1

     

    Participant
    March 25, 2024

    Hello Lilybiri,
    Thank you for your response.
    I tried your solution. However, it still doesn't work - when reentering the course, the variable only shows 2.
    Any thoughts?

    The javascript I put:

    var v01js = window.cpAPIInterface.getVariableValue(“v01”); window.cpAPIInterface.setVariableValue(“v01”,v01js.toFixed(2));

    Lilybiri
    Legend
    March 25, 2024

    Hmmm...

    Which event do you use to trigger this advanced action?

    Which exact version of Captivate do you use? In all versions before version 12 the variables have no real type, they can be used for both strings, numbers, T/F.... etc.  Did you give that variable a default value to start with? How do you display it?