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

# Why can't Captivate Multiply?

Community Beginner ,
May 23, 2022 May 23, 2022

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

WHY??????????

Views

184

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

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

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.

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

...

5 Replies 5
Community Expert ,
May 24, 2022 May 24, 2022

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

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

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

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.

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
People's Champ ,
May 24, 2022 May 24, 2022

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.

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

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

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.

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

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.