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...
WHY??????????
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:
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
...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:
Copy link to clipboard
Copied
I ended up writing it like this:
window.cpAPIInterface.setVariableValue("var_bonusVolumeFormat", var_bonusVolume.toFixed(0));
But your way might be easier to understand.
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);
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.
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.