Skip to main content
Known Participant
September 30, 2015
Answered

Incrementing by decimal values acting weird

  • September 30, 2015
  • 1 reply
  • 957 views

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

This topic has been closed for replies.
Correct answer TLCMediaDesign

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

1 reply

RodWard
Community Expert
Community Expert
October 1, 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.

accamererAuthor
Known Participant
October 2, 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?

RodWard
Community Expert
Community Expert
October 2, 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.