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

A Calculator that Rounds

New Here ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

I have created a calcuator using Captivate to help calcualte fees for our compnay.  The problem is I need to round it to the nearst dollar and I cannot for the life of me figure it out.  I know I will need to run a java script but does anyone have an idea on how to do this?  Below is my advanced action so I need to round the variable TotaltoDMV.   Any instructions you have is greatly appreicated. Capture.PNG

Views

276

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

Advisor , Jul 09, 2020 Jul 09, 2020

You'll need to execute some JavaScript at the appropriate place in your sequence of expressions.

 

For your JavaScript window...

 

TotaltoDMV = (Math.round(TotaltoDMV));

 

Votes

Translate

Translate
Advisor ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

You'll need to execute some JavaScript at the appropriate place in your sequence of expressions.

 

For your JavaScript window...

 

TotaltoDMV = (Math.round(TotaltoDMV));

 

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 ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

That is indeed the expression in JS. Of course I am NOT a JS expert but whenever I use JS in an advanced or shared action where variables are used which have been calculated in the advanced action, or their value needs to be changed I needed a lot more in the JS window. Maybe that has changed in the most recent version of CP?

Totally agree with Rod that CpExtra widget is a perfect solution if you don't want to plunge into upgrading your JS skills (and for many other features which are lacking in Captivate like the grey highlighting of answers in question slides not taking care of the background color). Beware: it can be rewarding to learn JavaScript, it is just an alternative.

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
Advisor ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

I started using JavaScript in my Captivate projects with Captivate 9. I like to think of it as creating my actions manually. I have never needed to add much to make it work.

The test is simple -  I made three quick buttons and a shape to display a variable that I called  myVar. Each button is set to Execute JavaScript and the code for each button is shown. It is that simple.

One will set the value, one will round to nearest whole number, and one will round to two decimals.

You'll need to clarify what you mean by warning others that JavaScript is an alternative that can be rewarding. I believe both statements are true but I guess I just don't understand why folks should  "Beware..."

rounding.gif

 

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 ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Because they may give a wrong interpretation to what I wrote. Often happens as you prove again.

You are writing out the full action in JS,  which is great. The OP has an advanced action which is doing almost the same with the exception of formatting the value of the last variable. You cannot just insert that simple mathematical function in that case, you need to get the value of the Cp variable, convert it and restore the result to the Cp variable.  There are three ways to solve this situation,

  • Use a full JS workflow, and I stated that this is a good alternative as long as you don't have to explain it to clients.
  • Use the existing advanced action and embed a JS script which often is my workflow
  • Use the existing advanced action and the CpExtra widget for the formatting. Since not all clients are prepared to buy that (too cheap) widget, I cannot always use that workflow.

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
Advisor ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

If we go back to my original response...

I am suggesting that they drop an  Execute Javascript  line into their list of actions so that the rounding can take place in the sequence where they need it to happen. If I am not mistaken - that sounds like bullet point number two in your last post.

If I take some series of expressions like the OP did and drop in an execute JavaScript line where I place my single line of JavaScript - it works just fine. How else did you think I was going to insert the code?

 

integrate.gif

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 ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

Because that never works for me. Reason why I asked if something has changed.

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
Advisor ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

I would encourage you to take 10 minutes and recreate what I did in that little graphic.

I think there is enough information there to do it.

Does it work for you?

 

I've really only ever used it this way - with the exception being when I create a custom animation to bring in as an HTML5 Animation. In that case, I just put the JavaScript inside of a <script> tag and save it as an  html  file before zipping it up and bringing it to the Captivate stage.

 

I'm no JavaScript expert either - I know just enough to know that I don't know very much.

Like I said, I consider what I do as simply crafting advanced actions manually - and I love it for many reasons.

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
New Here ,
Jul 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

It works!  Thank you Stagprime!

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
Advisor ,
Jul 20, 2020 Jul 20, 2020

Copy link to clipboard

Copied

LATEST

Glad to hear it!

Thanks for the update.

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 ,
Jul 09, 2020 Jul 09, 2020

Copy link to clipboard

Copied

If you happen to have the CpExtra HTML5 widget, then you have lots of options for rounding numbers and displaying values to a specific number of decimals.

https://widgetking.github.io/cpextra/variables/command.html#xcmndround

https://widgetking.github.io/cpextra/variables/command.html#xcmndroundto

 

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