# Variable Help

Nov 08, 2013

I have set up some numeric variables and triggers to do multiplication and my output comes out with 2 decimal places. for example

Learner inputs 350 products sold which is then divided by 42 (number of products yielded per case of sauce) and gets the result of 8.33. This means the learner would need to order 8.33 cases of sauce to make the 350 products. The problem is that the learner can not order partial cases and would need to round up to the next case,

What I would like to do is strip out the decimal places and have the answer round up to the next highest value. In this example 9.

Is this possible?

###### 13 Replies

You could use a JavaScript with the ceil() method (some info here) to round up your numbers, like in this example.

Owen Holt said:

Hi Owen, I'm probably wrong, but I don't think this solution rounds UP to the nearest integer and that's what Danny needs. Normal rounding would turn 8.33 into 8, and 8.51 into 9. It sounded like Danny wanted to round up in every case.

The concept is the same.

Step 1: Divide by 10,000,000 and your decimal place will move 7 spots to the left. Storyline will round that last position.

Examples:

1. 189.678543 becomes 0.0000190
2. 8.33 becomes 0.0000008
3. 12.5 becomes 0.0000013

Step 2: Multiply by 10,000,000

Examples from above:

1. 0.0000190 becomes 190
2. 0.0000008 becomes 8
3. 0.0000013 becomes 13
I think that fits the requirement.....

AH - Skip that.

I missed the rounding UP part

as opposed to just rounding...

Hi Danny! Looks like you are getting some assistance here

Michael Hinze said:

You could use a JavaScript with the ceil() method (some info here) to round up your numbers, like in this example.

That sounds like it will work but I am not sure how to make javascript work. Can you provide the story file from your example and let me look at it for reference?

Danny Evans said:

Michael Hinze said:

You could use a JavaScript with the ceil() method (some info here) to round up your numbers, like in this example.

That sounds like it will work but I am not sure how to make javascript work. Can you provide the story file from your example and let me look at it for reference?

See attached .story file. Hope that gets you started.

Michael Hinze said:

Danny Evans said:

Michael Hinze said:

You could use a JavaScript with the ceil() method (some info here) to round up your numbers, like in this example.

That sounds like it will work but I am not sure how to make javascript work. Can you provide the story file from your example and let me look at it for reference?

See attached .story file. Hope that gets you started.

That is totally awesome and totally worked.  You are a life saver.  Thanks so much..

Danny Evans said:

Michael Hinze said:

Danny Evans said:

Michael Hinze said:

You could use a JavaScript with the ceil() method (some info here) to round up your numbers, like in this example.

That sounds like it will work but I am not sure how to make javascript work. Can you provide the story file from your example and let me look at it for reference?

See attached .story file. Hope that gets you started.

That is totally awesome and totally worked.  You are a life saver.  Thanks so much..

Hi Danny, glad to hear that file works for you.

I just tried a non-java solution that works fine.
I have a numeric text entry field where you can enter your number with the following triggers:

1. Add 0.49 to NumericEntry when the control looses focus. (Any decimal below .5 will become greater than .5 as a result but a whole number will still be below the .5 decimal threshold and will not be rounded up).
2. Divide NumericEntry by 10000000 When the control looses focus. (Step one of rounding by taking advantage of storylines 7 decimal places limit.)
3. Multiply NumericEntry by 10000000 when the control looses focus. (Step two of rounding.)

This will work as long as you don't have a number with a decimal point of .0099999 or lower.

This would only occur at the following thresholds:

1 / >100

2 / >200

3 / >300

etc.

But since you control the equations.... you can avoid this issue.

That was determination Owen Love it!

Thanks for sharing as well.