## A Calculator that Rounds

New Here ,
Jul 09, 2020

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.

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

TotaltoDMV = (Math.round(TotaltoDMV));

Views

104

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## A Calculator that Rounds

New Here ,
Jul 09, 2020

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.

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

TotaltoDMV = (Math.round(TotaltoDMV));

Views

105

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 09, 2020 0
10 Replies 10
Jul 09, 2020

Copied

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

TotaltoDMV = (Math.round(TotaltoDMV));

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 09, 2020 1
Most Valuable Participant ,
Jul 10, 2020

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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 10, 2020 0
Jul 10, 2020

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 10, 2020 0
Most Valuable Participant ,
Jul 10, 2020

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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 10, 2020 0
Jul 10, 2020

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?

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 10, 2020 0
Most Valuable Participant ,
Jul 10, 2020

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 10, 2020 0
Jul 10, 2020

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.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 10, 2020 0
New Here ,
Jul 20, 2020

Copied

It works!  Thank you Stagprime!

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 20, 2020 0
LATEST
Jul 20, 2020

Copied

Thanks for the update.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 20, 2020 0
Jul 09, 2020

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 09, 2020 0