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

Why can't Captivate Multiply?

Community Beginner ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

As I try to turn decimals into a percent by multiplying decimals by 100, I get this funkiness. 

 

Expression = var_a * 100

var_a = .07

 

should give me 7 correct? Instead it gives me this...

 

Screen Shot 2022-05-23 at 2.49.22 PM.png

WHY??????????

 

Views

168

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , May 24, 2022 May 24, 2022

You cannot format the number of decimals in Captivate, you need to do that using JS. I have some examples here:

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

In your case you could choose to add those lines to your advanced action:

var perc = window.cpAPIInterface.getVariableValue(“var_a”);  window.cpAPIInterface.setVariableValue(“var_a”,toFixed(0));

Votes

Translate

Translate
People's Champ , May 24, 2022 May 24, 2022

Technically is better to use Math.round instead of toFixed(0) as toFixed returns a string and you could not do any further calculations with the result of toFixed.

 

Also, it has nothing to do with Captivate being funky, it is JavaScript that cannot accurately represent certain numbers in floating point binary, so you get those results. 

 

So with JavaScript just add this to your action:

 

Since you do not show what variable is being set with the result of your expression, I'll just use the vari

...

Votes

Translate

Translate
Community Expert ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

You cannot format the number of decimals in Captivate, you need to do that using JS. I have some examples here:

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

In your case you could choose to add those lines to your advanced action:

var perc = window.cpAPIInterface.getVariableValue(“var_a”);  window.cpAPIInterface.setVariableValue(“var_a”,toFixed(0));

Votes

Translate

Translate

Report

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 Beginner ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

LATEST

I ended up writing it like this:
window.cpAPIInterface.setVariableValue("var_bonusVolumeFormat", var_bonusVolume.toFixed(0));
But your way might be easier to understand.

Votes

Translate

Translate

Report

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 ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Technically is better to use Math.round instead of toFixed(0) as toFixed returns a string and you could not do any further calculations with the result of toFixed.

 

Also, it has nothing to do with Captivate being funky, it is JavaScript that cannot accurately represent certain numbers in floating point binary, so you get those results. 

 

So with JavaScript just add this to your action:

 

Since you do not show what variable is being set with the result of your expression, I'll just use the variable "result"

Math.round(window.result);

Votes

Translate

Translate

Report

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 ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

Thanks, David. I took this from an example where no further calculations were needed, since it was an end result. OP used the variable var_a.

Votes

Translate

Translate

Report

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 Beginner ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

Thank you both! I ended up using javascript toFixed(0) because it was just a display issue. I will use Math.Round when I need do more math to it.

Votes

Translate

Translate

Report

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