Variable Help
Nov 08, 2013
By
Danny Evans
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.
Check out the thread here (link) for a non javascript solution.
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:
Step 2: Multiply by 10,000,000
Examples from above:
AH - Skip that.
I missed the rounding UP part
as opposed to just rounding...
Hi Danny! Looks like you are getting some assistance here
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..
Glad to hear it Danny! Thanks Michael
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:
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.
This discussion is closed. You can start a new discussion or contact Articulate Support.