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

Incrementing by decimal values acting weird

Explorer ,
Sep 30, 2015 Sep 30, 2015

Wondering if anyone has encountered this problem and what you did to fix it:

When I try to increment or decrement a variable by .1, it returns .1, .200, .300, etc. After the first inc/decrement, the decimal places will extend to however long (in pixels) I have my displayed variable text set to. So if I start with a var which on the screen looks like: $$PrimaryRate$$, and extend the text box out beyond that text string length, then set it to 1 and then use a button to consecutively increment 1 by .1, it produces something like the following values: 1.1, 1.20000000000, 1.30000000000, etc. I tried just shortening the text box to hide the extra decimal places, but that only works until you hit the 10s. Then you lose the decimal place due to it being covered up by the short text box. It gets worse as you go up by more places.

I think what is needed is the ability to specify the decimal places allowed for a variable (set to 1, 2 or 3 places usually), similar to PDF form field values, but I don't see that setting anywhere in CP8 (my current version). Am I just missing that?

Also bummed about variables not displaying my chosen font, but that's another thread here somewhere...

Thanks,

Alan

942
Translate
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 1 Correct answer

People's Champ , Oct 02, 2015 Oct 02, 2015

You can put these 2 functions in the head of the html page. Call incUp() or incDn() in the JavaScript window.

function incUp()
{
var tempVal = Number(window.cpAPIInterface.getVariableValue("myNumber"));
tempVal += .1;
window.cpAPIInterface.setVariableValue("myNumber", tempVal.toFixed(1));
}

function incDn()
{
var tempVal = Number(window.cpAPIInterface.getVariableValue("myNumber"));
tempVal -= .1;
window.cpAPIInterface.setVariableValue("myNumber", tempVal.toFixed(1));
}

Translate
Community Expert ,
Sep 30, 2015 Sep 30, 2015

Captivate's Advanced Actions have no Rounding option. You may need to search on the forums for how to use JavaScript to achieve the rounding of a variable value.

Translate
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
Explorer ,
Oct 01, 2015 Oct 01, 2015

Thanks for the answer Rod. I've been trying various solutions but nothing working yet. Found some good JS info re: decimals on Stack overflow. Can you or someone point to a working CP8 example?

Translate
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 ,
Oct 01, 2015 Oct 01, 2015

I don't have one I can give you at this point.  Will be doing a lot more in the area of JavaScript in the near future.  Stay tuned.

Translate
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 ,
Oct 02, 2015 Oct 02, 2015

You can put these 2 functions in the head of the html page. Call incUp() or incDn() in the JavaScript window.

function incUp()
{
var tempVal = Number(window.cpAPIInterface.getVariableValue("myNumber"));
tempVal += .1;
window.cpAPIInterface.setVariableValue("myNumber", tempVal.toFixed(1));
}

function incDn()
{
var tempVal = Number(window.cpAPIInterface.getVariableValue("myNumber"));
tempVal -= .1;
window.cpAPIInterface.setVariableValue("myNumber", tempVal.toFixed(1));
}

Translate
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
Explorer ,
Oct 02, 2015 Oct 02, 2015

Wow! Thanks for the script Dave. I'm off today but I'll try it on Monday and see how it goes. Looks like it should work fine. If I have time this weekend I'll set up a test at home. Thanks again.

Translate
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
Explorer ,
Oct 05, 2015 Oct 05, 2015
LATEST

Just wanted to mention that thanks to Dave at TLCMediaDesign, the above script did work and I would recommend this method to anyone trying to increment values by decimals.

To control/use JavaScript from CP, via the head of an HTML document, you:

1. set up an 'Execute JavaScript' action on a button in CP, using the name of the function (here it's incUp(); or incDn(); as the only statement in the script window.

2. Publish your CP file to HTML5 (turn off Scorm for now)


3. Using your favorite HTML editor, compose or copy the function (as shown above) into the head of the HTML doc that captivate publishes ( between the <script> tags) Remember to replace 'myNumber' with the CP variable you're trying to increment.


4.  Next, open the HTML file in a browser to test it. Edit and repeat as necessary until it works the way you need it to. For incrementing and rounding decimals this is by far easier and smoother than anything you could do in Captivate.


I'm sure there are better explanations but hopefully that will help someone at least get started.

Translate
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